Posts

Minimum indexed character

  Easy Accuracy: 50.58% Submissions: 21507 Points: 2 Given a string  str  and another string  patt . Find the first position (considering 0-based indexing) of the character in  patt  that is present at the minimum index in  str . Example 1: Input: str = geeksforgeeks patt = set Output: 1 Explanation: e is the character which is present in given patt "geeksforgeeks" and is first found in str "set". First Position of e in str is 1. Example 2: Input: str = adcffaet patt = onkl Output: -1 Explanation: There are none of the characters which is common in patt and str. Your Task: You only need to complete the function minIndexChar()  that returns the index of answer in str or returns -1 in case ...

Right most non zero digit

Right most non zero digit Easy Accuracy: 39.12% Submissions: 8042 Points: 2 You will be given an array A of N non-negative integers. Your task is to find the rightmost non-zero digit in the product of array elements. Example 1: Input: N = 4, A = {3, 23, 30, 45} Output: 5 Explanation: Product of these numbers are 93150. Rightmost non-zero digit is 5. Example 2: Input: N = 5, A = {1, 2, 3, 4, 5} Output: 2 Explanation: Product of these numbers are 120. Rightmost non-zero digit is 2....

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
  Count numbers containing 4   Basic  Accuracy:   48.18%  Submissions:   2010  Points:   1 Count the numbers between 1 to  N  containing 4 as a digit.   Example 1: Input: N = 9 Output: 1 Explanation: 4 is the only number between 1 to 9 which contains 4 as a digit. Example 2: Input: N = 14 Output: 2 Explanation: 4 and 14 are the only number between 1 to 14 that contains 4 as a digit.   Your Task: You don't need to read input or print anything. Your task is to complete the function  countNumberswith4()  which takes an Integer N as input and returns the answer.

heck if array contains contiguous integers with duplicates allowed

Easy  Accuracy:   65.11%  Submissions:   761  Points:   2 Given an array of n integers(duplicates allowed). Print “Yes” if it is a set of contiguous integers else print “No”. Example 1: ​ Input : arr[ ] = {5, 2, 3, 6, 4, 4, 6, 6} Output : Yes Explanation: The elements  of array form a contiguous set of integers which is {2, 3, 4, 5, 6} so the output is "Yes". Example 2: Input : arr[ ] = {10, 14, 10, 12, 12,  13, 15} Output : No Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function  areElementsContiguous()  that takes an array  (arr) , sizeOfArray  (n) , and return the  true  if it is a set of contiguous integers else print  false . The driver code takes care of the printing.

Delete without head pointer

You are given a pointer/ reference to the node which is to be deleted from the linked list of   N  nodes. The task is to delete the node. Pointer/ reference to head node is not given.  Note:  No head reference is given to you. It is guaranteed that the node to be deleted is   not a tail node   in the linked list. Example 1: Input: N = 2 value[] = {1,2} node = 1 Output: 2 Explanation: After deleting 1 from the linked list, we have remaining nodes as 2. Example 2: Input: N = 4 value[] = {10,20,4,30} node = 20 Output: 10 4 30 Explanation: After deleting 20 from the linked list, we have remaining nodes as 10, 4 and 30. Your Task: You only need to complete the  function deleteNode  that takes  reference  to the node that needs to be  deleted . The  printing  is done  automatically  by the  driver code .

Sum of Big Integers

Given two positive integers   X   and   Y . You have to add two integers and output their   sum .   Example 1: Input: X = 3, Y = 4 Output: 7 Explanation: Sum of X and Y is 7   Example 2: Input: X = 8, Y = 2 Output: 10 Explanation: Sum of X and Y is 10.   Your Task: Your task is to complete the function  add () which accepts BigIntegers x and y as input parameters, and returns their sum.

Find smallest values of x and y

Given two values   ‘a’   and   ‘b’   that represent coefficients in “ ax – by = 0 ”, find the smallest values of x and y that satisfy the equation. It may also be assumed that x > 0, y > 0, a > 0 and b > 0. Example 1: Input: a = 25, b = 35 Output: 7 5 Explaination: 25*7 - 35*5 = 0. And x = 7 and y = 5 are the least possible values of x and y to get the equation solved. Example 2: Input: a = 3, b = 7 Output: 7 3 Explaination: For this case x = 7 and y = 3 are the least values of x and y to satisfy the equation. Your Task: You do not need to read input or print anything. Your task is to complete the function  findXY()  which takes a and b as input parameters and returns the least possible values of x and y to satisfy the equation.

Repeated sum of digits

Given an integer N, recursively sum digits of N until we get a single digit.  The process can be described below If N < 10 digSum(N) = N Else digSum(N) = Sum(digSum(N))   Example 1: Input: N = 1234 Output: 1 Explanation: The sum of 1+2+3+4 = 10, digSum(x) == 10 Hence ans will be 1+0 = 1     Example 2: Input: N = 9999 Output: 9 Explanation: Check it yourself.   Your Task: You don't need to read input or print anything. Your task is to complete the function repeatedSumOfDigits() which takes an integer N and returns the repeated sum of digits of N.

occurrence 2 as a gidit

 x=0 for i in range(23):     x+=str(i).count('2') print(x)

Expression Tree

Given a full binary expression tree consisting of basic binary operators (+ , – ,*, /) and some integers, Your task is to evaluate the expression tree. Example 1: Input: + / \ * - / \ / \ 5 4 100 20 Output: 100 Explanation: ((5 * 4) + (100 - 20)) = 100 Example 2: Input: - / \ 4 7 Output: -3 Explanation: 4 - 7 = -3 Your Task:   You dont need to read input or print anything. Complete the function  evalTree()  which takes root node as input parameter and returns an integer denoting the result obtained by simplifying the expression tree. Expected Time Complexity:  O(N)

Count pairs from two linked lists whose sum is equal to a given value

Difficulty Level :   Easy Last Updated :   07 Jan, 2021 Given two linked lists(can be sorted or unsorted) of size  n1  and  n2  of distinct elements. Given a value  x . The problem is to count all pairs from both lists whose sum is equal to the given value  x . Note:  The pair has an element from each linked list. Examples:    Input : list1 = 3->1->5->7 list2 = 8->2->5->3 x = 10 Output : 2 The pairs are: (5, 5) and (7, 3) Input : list1 = 4->3->5->7->11->2->1 list2 = 2->3->4->5->6->8-12 x = 9 Output : 5 # Python3 implementation to count pairs from both linked # lists whose sum is equal to a given value # A Linked list node class Node: def __init__(self,data): self.data = data self.next = None # function to insert a node at the # beginning of the linked list def push(head_ref,new_data): new_node=Node(new_data) #new_node.data = new_...

Trie | (Insert and Search)

Trie is an efficient information retrieval data structure. Use this data structure to store Strings and search strings. Your task is to use TRIE data structure and search the given string A. If found print 1 else 0. Example 1: Input: N = 8 key[] = {the,a,there,answer,any,by,   bye,their} search = the Output: 1 Explanation: the is present in the given string "the a there answer any by bye their" Example 2: Input: N = 8 key[] = {the,a,there,answer,any,by,   bye,their} search = geeks Output: 0 Explanation: geeks is not present in the given string "the a there answer any by bye their" Your Task: Complete  insert  and  search  function and return  true  if key is present in the formed trie else  false  in the search function. (In case of true, 1 is printed and false, 0 is printed by the driver's code. Expected Time Complexity:  O(M+|search|). Expected Auxiliary Space:  O(M). M = sum of the length of all strings...

Generate Binary Numbers

Given a number   N . The task is to generate and print all   binary numbers with decimal values   from   1 to N . Example 1: Input: N = 2 Output: 1 10 Explanation: Binary numbers from 1 to 2 are 1 and 10. Example 2: Input: N = 5 Output: 1 10 11 100 101 Explanation: Binary numbers from 1 to 5 are 1 , 10 , 11 , 100 and 101.   Your Task: You only need to complete the  function  generate() that takes  N  as  parameter  and returns vector of strings denoting binary numbers. Expected Time Complexity :  O(N log 2 N) Expected Auxilliary Space :  O(N log 2 N)