You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in the example
Tag: data-structures
Create a list of List from an Array
How can i create a list of List from Array eg: int[] arr = {3, 1, 5, 8, 2, 4}. Such that the lists in the List have only two elements eg: [[3,1], [5,8], [2,4]]. So far i have tried code below but it return only lists with one element,I can’t figure out where i went wrong. Result: [[3], [1],
Custom LinkedList constructor with array as a parameter
I’ve written this program to implement a LinkedList. There are 2 classes: Node and IntLinkedList and the relationship between them is aggregation. In the IntLinkedList class, the constructor’s parameter is an array and I’ve tried to use a for-each loop to add the data of the array to the linked list. Here is my code: Node.java IntLinkedList.java I’ve tried for
Maximum number of tasks to be performed
I’m stucking in a problem. I know dp can be applied here, but not getting it. Consider a part of the positive number line starting at 0 and ending at 10^9. You start at 0 and there are N tasks can be performed. The ith task is at l[i] and requires t[i] time to be performed. To perform ith task,
Search Suggestions System
Below is the problem statement and below it , is my solution using TrieNode Data structure but My ans is wrong and i am not able to understand where my code gone wrong , please help …… Given an array of strings products and a string searchWord. We want to design a system that suggests at most three product names
print numbers from 1 to 1000 digit number – interview question
I had an interview and I’ve been asked to print numbers from 1 to a 1000 digit number – 1, 2, 3, . . . ., 999999999999999999999999999999999999999999999999…….. I couldn’t solve it but I’m still looking for the best way to do it, because obviously, you cant use integers or floats in a case like this and because it’s a job
Down to Zero II
This is the question: You are given Q queries. Each query consists of a single number N . You can perform any of the operations on in each move: If we take 2 integers a and b where N=a*b (a ,b cannot be equal to 1), then we can change N=max(a,b) Decrease the value of N by 1 . Determine
What is the quickest way to determine if two elements are in the same row or column in a 2D array?
As part of one of my programs, I’m trying to check if two elements in a 2D array are part of the same row or column. I know there might be many ways to go about this, mainly with loops and by iterating through the array, but I was just wondering: is there any quick way to determine this? Let’s
Make a moving cursor using doubly linked list in java
I’m trying to write a code for a simple moving cursor in java. I have to use doubly linked list. Also I should implement doubyLinkedList class myself. In this program first we take an integer like n from user as number of lines. Then we take n lines of input. Each line contains only one character which can be <
Way to overcome fail-fast iterator in HashMap
In competitive programming, I was solving a given problem – given an array nums of non-negative integers, and a target sum S, we have to find out the number of ways we can obtain target sum from sum of given numbers (where each nums[i] can be taken as nums[i] or -nums[i]. Although I came across some solutions that mainly relied