Posts

Showing posts from July, 2021

Subarrays with sum K

Medium  Accuracy:   65.67%  Submissions:   5548  Points:   4 Given an unsorted array of integers, find the number of continuous subarrays having sum exactly equal to a given number k. Example 1: Input: N = 5 Arr = {10 , 2, -2, -20, 10} k = -10 Output: 3 Explaination: Subarrays: arr[0...3], arr[1...4], arr[3..4] have sum exactly equal to -10. Example 2: Input: N = 6 Arr = {9, 4, 20, 3, 10, 5} k = 33 Output: 2 Explaination: Subarrays : arr[0...2], arr[2...4] have sum exactly equal to 33. Your Task: You don't need to read input or print anything. Your task is to complete the function  findSubArraySum()  which takes the array  Arr[]  and its size  N  and  k  as input parameters and returns the count of subarrays.

Rotate by 90 degree

Medium  Accuracy:   53.41%  Submissions:   12494  Points:   4 Given a   square  matrix[][]  of size  N x N . The task is to rotate it by  90 degrees in an anti-clockwise  direction without using any extra space. Example 1: Input: N = 3 matrix[][] = [[1 2 3],   [4 5 6],   [7 8 9]] Output: 3 6 9  2 5 8  1 4 7 Your Task: You only need to implement the given function  rotate() . Do not read input, instead use the arguments given in the function. 

Minimum element in BST

Basic  Accuracy:   62.66%  Submissions:   48952  Points:   1 Given a  Binary Search Tree . The task is to find the minimum element in this given BST. Example 1: Input:            5         /    \        4      6      /        \    3          7    /     1 Output: 1 Example 2: Input:              9              \               10               \                 11 Output: 9 Your Task: The task is to complete the function  minValue()  which takes root as the argument and retu...

Merge Sort on Doubly Linked List

Medium  Accuracy:   60.43%  Submissions:   9631  Points:   4 Given Pointer/Reference to the head of a doubly linked list of N nodes, the task is to  Sort the given doubly linked list using Merge Sort  in both  non-decreasing  and  non-increasing  order. Example 1: Input: N = 8 value[] = {7,3,5,2,6,4,1,8} Output: 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 Explanation: After sorting the given linked list in both ways, resultant matrix will be as given in the first two line of output, where first line is the output for non-decreasing order and next line is for non- increasing order. Example 2: Input: N = 5 value[] = {9,15,0,-1,0} Output: -1 0 0 9 15 15 9 0 0 -1 Explanation: After sorting the given linked list in both ways, the resultant list will be -1 0 0 9 15 in non-decreasing order and 15 9 0 0 -1 in non-increasing order. Your Task: The task is to complete the function  sortDoubly () which sorts the doubly linked list. The ...

Change Bits

Easy  Accuracy:   72.48%  Submissions:   1390  Points:   2 Given a number  N,  complete the following tasks, Task 1. Generate a new number from N by changing the zeroes in the binary representation of N to 1. Task  2. Find the difference between N and the newly generated number.   Example 1: Input: N = 8 Output: 7 15 Explanation: There are 3 zeroes in binary representation of 8. Changing them to 1 will give 15. Difference between these two is 7. Example 2: Input: N = 6 Output: 1 7 Explanation: There is 1 zero in binary representation of 6. Changing it to 1 will give 7. Difference between these two is 1.   Your Task: You don't need to read input or print anything. Your task is to complete the function  changeBits()  which takes an integer N as input parameter and returns a list of two integers containing the difference and the generated number respectively.

While loop- printTable

Easy  Accuracy:   58.02%  Submissions:   13069  Points:   2 While loop is another loop like for loop but unlike for loop it only checks for one condition. Here, we will use  while loop  and print a number  n's table in reverse order. Example 1: Input:  n = 1 Output: 10 9 8 7 6 5 4 3 2 1 Example 2: Input: n = 2 Output: 20 18 16 14 12 10 8 6 4 2 https://youtu.be/QY7fDniYjmA #User function Template for python3 class Solution: def printTable(self, n): multiplier = 10 while(multiplier): print(multiplier * n, end = " ") multiplier -= 1 print() #{ # Driver Code Starts #Initial Template for Python 3 if __name__ == '__main__': T=int(input()) for i in range(T): n = int(input()) obj = Solution() obj.printTable(n) # } Driver Code Ends

Quick Sort on Linked List

Sort the given  L inked  L ist using quicksort. which takes  O(n^2)  time in worst case and  O(nLogn)  in average and best cases, otherwise you may get TLE. Input: In this problem, method takes 1 argument: address of the  head  of the linked list. The function should not read any input from stdin/console. The struct Node has a data part which stores the  data  and a next pointer which points to the  next  element of the linked list. There are multiple test cases. For each test case, this method will be called individually. Output: Set  *headRef  to head of resultant linked list. User Task: The task is to complete the function  quickSort () which should set the *headRef to head of the resultant linked list. Constraints: 1<= T <=100 1<= N <=200 Note:  If you use "Test" or "Expected Output Button" use below example format