🔥2❤1👍1
Day 69👾:
Given the head of two singly linked listsnum1
andnum2
representing two non-negative integers. The task is to return the head of the linked list representing the sum of these two numbers.
For example,num1
represented by the linked list :1 -> 9 -> 0
, similarlynum2
represented by the linked list:2 -> 5
. Sum of these two numbers is represented by2 -> 1 -> 5
.
Note: There can be leading zeros in the input lists, but there should not be any leading zeros in the output list.
🔥3👍1🍾1👨💻1
Day 70👾:
You are given a special linked list with n nodes where each node has two pointers a next pointer that points to the next node of the singly linked list, and a random pointer that points to the random node of the linked list.
Construct a copy of this linked list. The copy should consist of the same number of new nodes, where each new node has the value corresponding to its original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list, such that it also represent the same list state. None of the pointers in the new list should point to nodes in the original list.
Return the head of the copied linked list.
NOTE : Original linked list should remain unchanged.
🔥2👏2❤1👍1
Day 72👾:
Given a head of the singly linked list. If a loop is present in the list then return thefirst node
of the loop else returnNULL
.
Custom Input format:
A head of a singly linked list and a pos (1-based index
) which denotes the position of the node to which the last node points to. Ifpos = 0
, it means the last node points to null, indicating there is no loop.
👍2🔥2⚡1👏1
Day 73👾:
Given the head of a linked list that may contain a loop. A loop means that the last node of the linked list is connected back to a node in the same list. The task is to remove the loop from the linked list (if it exists).
Custom Input format:
A head of a singly linked list and a pos (1-based index) which denotes the position of the node to which the last node points to. If pos = 0, it means the last node points to null, indicating there is no loop.
The generated output will be true if there is no loop in list and other nodes in the list remain unchanged, otherwise, false.
👍4🔥1👏1
Day 74👾:
Design a data structure that works like a LRU Cache. Here cap denotes the capacity of the cache and Q denotes the number of queries. Query can be of two types:
PUT x y: sets the value of the key x with value y
GET x: gets the value of key x if present else returns -1.
The LRUCache class has two methods get() and put() which are defined as follows.
get(key): returns the value of the key if it already exists in the cache otherwise returns -1.
put(key, value): if the key is already present, update its value. If not present, add the key-value pair to the cache. If the cache reaches its capacity it should remove the least recently used item before inserting the new item.
In the constructor of the class the capacity of the cache should be initialized.
❤2👍2⚡1🔥1🖕1
Day 77👾:
The n-queens puzzle is the problem of placing n queens on a(n × n)
chessboard such that no two queens can attack each other. Note that two queens attack each other if they are placed on the same row, the same column, or the same diagonal.
Given an integer n, find all distinct solutions to the n-queens puzzle.
You can return your answer in any order but each solution should represent a distinct board configuration of the queen placements, where the solutions are represented as permutations of[1, 2, 3, ..., n]
. In this representation, the number in the ith position denotes the row in which the queen is placed in the ith column.
For eg. below figure represents a chessboard[3 1 4 2]
.
👏3👍2❤1