Hi everyone!!
THE CODE WARS IS NOW LIVE!
Below are the questions and these are the criteria -
-
YOU HAVE TO ATTEMPT ALL QUESTIONS
-
YOU HAVE 2 HRS TO FINISH THE PROBLEMS AND SUBMIT YOUR LINK HERE IN THIS THREAD BY 2:30 PM
-
FSR STUDENTS WILL USE JAVASCRIPT TO SOLVE THE PROBLEMS AND DS STUDENTS WILL USE PYTHON
-
THE WINNERS WILL BE DECIDED BASED ON ACCURACY AND SPEED
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Question 1:
Given a linked list of N nodes such that it may contain a loop.
A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0.
Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming the loop.
Example 1:
Input:N = 3value[] = {1,3,4}X = 2Output: 1Explanation: The link list looks like1 -> 3 -> 4 ^ | |____| A loop is present. If you remove it successfully, the answer will be 1.
Example 2:
Input:N = 4value[] = {1,8,3,4}X = 0Output: 1Explanation: The Linked list does not contains any loop.
Example 3:
Input:N = 4value[] = {1,2,3,4}X = 1Output: 1Explanation: The link list looks like 1 -> 2 -> 3 -> 4^ ||______________|A loop is present. If you remove it successfully, the answer will be 1.
Your Task:
You don’t need to read input or print anything. Your task is to complete the function removeLoop() which takes the head of the linked list as the input parameter. Simply remove the loop in the list (if present) without disconnecting any nodes from the list.
Note: The generated output will be 1 if your submitted code is correct.
Expected time complexity: O(N)
Expected auxiliary space: O(1)
Constraints:
1 ≤ N ≤ 10^4
Question 2:
Given an unsorted array Arr of size N of positive integers. One number ‘A’ from set {1, 2,…,N} is missing and one number ‘B’ occurs twice in array. Find these two numbers.
Example 1:
Input:N = 2Arr[] = {2, 2}Output: 2 1Explanation: Repeating number is 2 and smallest positive missing number is 1.
Example 2:
Input:N = 3Arr[] = {1, 3, 3}Output: 3 2Explanation: Repeating number is 3 and smallest positive missing number is 2.
Your Task:
You don’t need to read input or print anything. Your task is to complete the function findTwoElement() which takes the array of integers arr and n as parameters and returns an array of integers of size 2 denoting the answer ( The first index contains B and second index contains A.)
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
2 ≤ N ≤ 10^5
1 ≤ Arr[i] ≤ N
Question 3:
Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N. Find the missing element.
Example 1:
Input:N = 5A[] = {1,2,3,5}Output: 4
Example 2:
Input:N = 10A[] = {6,1,2,8,3,4,7,10,5}Output: 9
Your Task :
You don’t need to read input or print anything. Complete the function MissingNumber() that takes array and N as input parameters and returns the value of the missing number.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^6
1 ≤ A[i] ≤ 10^6
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
ALL THE BEST!
cc, @sumanth.medishetti provided the questions for this Code Wars