Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
You may not alter the values in the nodes, only nodes itself may be changed.
Only constant memory is allowed.
For example,
Given this linked list: 1->2->3->4->5
For k = 2, you should return: 2->1->4->3->5
For k = 3, you should return: 3->2->1->4->5
Seen this question in a real interview before?
Yes
No
When did you encounter this question?
last week
last month
last 3 month
last 6 month
more than 6 months
other
Which company?
Adobe
Aetion
Airbnb
Alibaba
Amazon
Apple
Baidu
Bloomberg
Cloudera
Coursera
Cryptic Studios
Dropbox
eBay
Epic Systems
Expedia
Facebook
Fallible
Games
Gilt Groupe
GoDaddy
Goo
Google
Hedvig
Houzz
Hulu
Indeed
Intuit
IXL
LinkedIn
LiveRamp
Lyft
MAQ Software
Mathworks
Microsoft
NetEase
Netsuite
Palantir
Palantir Technologies
Pinterest
Pocket Gems
Poynt
Pure
Pure Storage
Rackspace
Riot
Riot Games
Samsung
Snapchat
Square
Storage
Tencent
TinyCo
Twitter
Two Sigma
Uber
Valve
WAP
Works Applications
Yahoo
Yahoo!
Yelp
Zappos
Zenefits
Difficulty:Hard
Total Accepted:103.6K
Total Submissions:335.3K
Contributor:
LeetCode
Subscribe
to see which companies asked this question.