! CODE WARS - October!

Hey everyone! :wave: :wave:

After a brief hiatus, we are back with Code Wars for October! :rocket: :grin: :grin:

:rotating_light: The Code Wars will commence on Saturday 14th October at 12:30 PM!

:white_check_mark: Are you ready for the war??? :thinking:

cc @drishtinayak2828-TA @dharshinim.ug20.cs @shivtech1906 @poojagarva @Salunkheakash619 @shivendra1751 @Pratik-TA-FSR @sahityasingh1211 @ayushibatham60 @mohammedaliparkar342 @vaishnavitandon9499 @Vaishalim722 @utkarshkesharwani65 @kaushal.kk37 @dkdebarun666 @sindhiyadevit @shivrajrtandale98 @pirjadesimran815

13 Likes

:smile: Here’s some clarity for those who are new to the event! (WELCOME ABOARD! :people_hugging:)

1. What is Code Wars? :thinking:

:video_game: Code Wars is a monthly coding competition held organization wide for all ongoing batches! Students come together and test out their skills and understanding of the concepts they’ve learnt in the sessions and stand to become the winner and represent their batch publically! :dragon:

2. Why should I care? :face_with_raised_eyebrow:

:video_game: Well, this is not a mandatory event. If you want and have the time - you are more than welcomed to try it out! Winners will receive an official certificate which you can provide in your resumes! You get to have the opportunity of testing out your skills in a healthy competetive environment. You can also provide the projects you might do in Code Wars on LinkedIn to raise the standard of your profile!
You can also show-off your skills by posting your certificate on social media and tag us! We’ll cheer the loudest! :people_hugging: :partying_face:

3. What do I have to do? :face_with_peeking_eye:

:video_game: Not much! Clear your schedule for 14th October 12:30 PM. There will be coding problems this time which will be live on 12:30 PM. There will be a deadline within which you have to write the codes and share the links to this thread. You can write your codes on GitHub, CodePen or any other platform. Once you are done, share your submission link here along with your batchcode.

See you all soon! :wave: :wave:

5 Likes

How can I register for this event?

2 Likes

Hello… @abhishekadarsh21
There is no need to register for it. It will live on given time. The problems for code war will live on that given day and time and you should prepare for this. You can solve problem as mention tool for that problems. At last submit your coding link here. Simple…
I hope your doubt cleared…Let me know…

3 Likes

Hey Guys! :wave: :wave:

Looking forward to seeing you join us next week! :rocket:

:grin: We are excited, are you? :grinning:

4 Likes

how can i registered

1 Like

HI @golladurgasravani , please read the post carefully -


You don’t need to register. The Coding Problems will be shared on 14th October at 12:30 PM. Just be here at that time and complete the coding correctly within deadline, submit your link here in this thread and mention your batch code.

1 Like

Hey hey now!!! :wave: :wave:

:checkered_flag: Get ready for the Code Wars!

:point_right: The coding problems will be live here at 12:30 PM! tomorrow

You will have 2 hrs to solve the coding problems correctly and share your links here before 2:30 PM.

Any submissions after that time will not be considered. The winner will be the one who wrote the answers correctly and the fastest!

The winners of Code Wars will be delcared next week!

See you all tomorrow :smile:

2 Likes

Hi everyone!! :wave: :wave:

:rotating_light: THE CODE WARS IS NOW LIVE! :rotating_light:

Below are the questions and these are the criteria - :point_down: :point_down:

  1. YOU HAVE TO ATTEMPT ALL QUESTIONS

  2. YOU HAVE 2 HRS TO FINISH THE PROBLEMS AND SUBMIT YOUR LINK HERE IN THIS THREAD BY 2:30 PM

  3. FSR STUDENTS WILL USE JAVASCRIPT TO SOLVE THE PROBLEMS AND DS STUDENTS WILL USE PYTHON

  4. 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! :checkered_flag: :checkered_flag:

cc, @sumanth.medishetti provided the questions for this Code Wars :brown_heart:

2 Likes

Code-War/Code War Oct.ipynb at main · Ankit2080/Code-War (github.com)

1 Like

golladurga/DS290423-CODE-WAR (github.com)
DS290423.

1 Like

Problem 1: Remove Loop in Linked List

class Node:
def init(self, data):
self.data = data
self.next = None

def removeLoop(head):
slow = head
fast = head

# Detect loop
while fast and fast.next:
    slow = slow.next
    fast = fast.next.next
    if slow == fast:
        break

# If no loop is present
if not fast or not fast.next:
    return

# Find the start of the loop
slow = head
while slow.next != fast.next:
    slow = slow.next
    fast = fast.next

# Remove the loop
fast.next = None

Problem 2: Find the Repeating and Missing Number

def findTwoElement(arr, n):
xor = arr[0]
for i in range(1, n):
xor ^= arr[i]

for i in range(1, n+1):
    xor ^= i

# Now xor contains the xor of repeating and missing numbers
# Find the rightmost set bit
rightmost_set_bit = xor & -xor

x, y = 0, 0

# Divide the array elements into two groups based on rightmost set bit
for num in arr:
    if num & rightmost_set_bit:
        x ^= num
    else:
        y ^= num

# Divide 1 to N into two groups based on rightmost set bit
for i in range(1, n+1):
    if i & rightmost_set_bit:
        x ^= i
    else:
        y ^= i

# Determine which one is repeating and which one is missing
for num in arr:
    if num == x:
        return [x, y]
    elif num == y:
        return [y, x]

Problem 3: Find the Missing Number in an Array of Size N-1

def MissingNumber(arr, n):
total_xor = 1

# XOR of 1 to N
for i in range(2, n+1):
    total_xor ^= i

arr_xor = arr[0]
# XOR of elements in the array
for i in range(1, n-1):
    arr_xor ^= arr[i]

# Find the missing number
missing_number = total_xor ^ arr_xor
return missing_number
1 Like