educative.io

Node object fields in Java Recursion module Recursion With Data Structures Challenge 1

In “Challenge 1: Search for a Value in a Linked List” it is impossible to tell what the fields are on the object type “Node” from information provided in the prompt. I had to cheat and look at the solution to find these field names.

For anyone who runs into this, know that “Node.data” and “Node.next” are the field names you need to solve the problem.

Hey @Justin_Schneider

class Solution {
    public static Object search(Node head, int num) {
      // Write your code here
      // Do not change the input parameters
      // Change the return type of this function to "boolean"
      
      return 0; // To be modified according to your code should return "true" or "false"
    } 
} 

Two arguments are provided above

  • First head which is of Node type
  • Second num which is of int type

Since it is a challenge, we should know what kind of operations we can perform with Node data type. Also, Node data type was also used in the previous challenge, so I assume you have used them before. If you have still any query feel free to ask.

Happy learning,

Honestly I was just skipping around sections since I already use Java a lot at work, just refreshing myself on some examples.

I did, however, read everything in the ‘Recursion with Data Structures’ section before the Challenge, but the difference was it used “Node.value” instead of “Node.data” which is needed in the Challenge. So when I tried using “head.value” for the challenge solution I was surprised it didn’t work.

Hi @Justin_Schneider

We have written Node class at the backend for this solution; therefore, the variables name varied to the other course, Recursion with Data Structures. We feel sorry for any inconvenience and will try to be consistent on the platform, though these variable names are consistent throughout the course.

Happy learning,