We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Linked Lists
  4. Insert a node at a specific position in a linked list
  5. Discussions

Insert a node at a specific position in a linked list

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1306 Discussions, By:

votes

Please Login in order to post a comment

  • ed_andrews
    1 year ago+ 14 comments

    In the Java code there is a compilation error when I simply return a null.

    Solution.java:78: error: Illegal static declaration in inner class Solution.Result public static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode llist, int data, int position) { ^ modifier 'static' is only allowed in constant variable declarations Solution.java:109: error: cannot find symbol SinglyLinkedListNode llist_head = insertNodeAtPosition(llist.head, data, position); ^ symbol: method insertNodeAtPosition(SinglyLinkedListNode,int,int) location: class Solution 2 errors

    60|
    Permalink
    View more Comments..
  • beladiyahardik7
    7 years ago+ 15 comments

    Hey guys is there is any problem in test case. I think there is problem in the 2 4 because for that atleast we require 3 node . and if i am correct then please correct the input as soon as possible

    47|
    Permalink
    View more Comments..
  • varunrisbud
    7 years ago+ 5 comments

    This is NOT a properly designed test case. Output is getting swapped when linked list starts with 2. Dont waste your time on this question.

    38|
    Permalink
    View more Comments..
  • Hunter_
    7 years ago+ 2 comments

    Either the test case that the author has included is broken or they have incorrectly described the test data and how the function should work. I was only able to pass it by including some special case code to get rid of a head node with data=2 and insert a tail node with a data=2. This challenge should be deleted until the author can fix the issues.

    30|
    Permalink
  • alapanc21
    1 year ago+ 4 comments

    Can somebody help me with this error in java 8 ?

    Solution.java:78: error: Illegal static declaration in inner class Solution.Result public static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode llist, int data, int position) { ^ modifier 'static' is only allowed in constant variable declarations Solution.java:121: error: cannot find symbol SinglyLinkedListNode llist_head = insertNodeAtPosition(llist.head, data, position); ^ symbol: method insertNodeAtPosition(SinglyLinkedListNode,int,int) location: class Solution 2 errors

    20|
    Permalink
    View more Comments..
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature