Problem Of The Day
"Sequence Fun"
Solve the problem to win points
You have a sequence 2,5,16,65,........Given an integer n as input . You have to find the value at nth position in the sequence.
Example 1:
Input: n = 4
Output: 65
Example 2:
Input: n = 10
Output: 9864101
Your Task:
You don't need to read or print anything, Your task is to complete the function NthTerm() which takes n as input parameter and retruns value at nth position of the given sequence modulo 109 + 7.
Expected Time Compelxity: O(n)
Expected Space Complexity: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/sequence-fun5018/1
"Sequence Fun"
Solve the problem to win points
You have a sequence 2,5,16,65,........Given an integer n as input . You have to find the value at nth position in the sequence.
Example 1:
Input: n = 4
Output: 65
Example 2:
Input: n = 10
Output: 9864101
Your Task:
You don't need to read or print anything, Your task is to complete the function NthTerm() which takes n as input parameter and retruns value at nth position of the given sequence modulo 109 + 7.
Expected Time Compelxity: O(n)
Expected Space Complexity: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/sequence-fun5018/1
practice.geeksforgeeks.org
Sequence Fun | Practice | GeeksforGeeks
You have a sequence 2,5,16,65,........Given an integer n as input . You have to find the value at nth position in the sequence.
Example 1:
Input: n = 4
Output: 65
Example 2:
Input: n = 10
Output: 9864101
Example 1:
Input: n = 4
Output: 65
Example 2:
Input: n = 10
Output: 9864101
π6β€2
Problem Of The Day
"Phone directory"
Solve the problem to win points
Given a list of contacts contact[] of length n where each contact is a string which exist in a phone directory and a query string s. The task is to implement a search query for the phone directory. Run a search query for each prefix p of the query string s (i.e. from index 1 to |s|) that prints all the distinct contacts which have the same prefix as p in lexicographical increasing order. Please refer the explanation part for better understanding.
Note: If there is no match between query and contacts, print "0".
Example 1:
Input:
n = 3
contact[] = {"geeikistest", "geeksforgeeks",
"geeksfortest"}
s = "geeips"
Output:
geeikistest geeksforgeeks geeksfortest
geeikistest geeksforgeeks geeksfortest
geeikistest geeksforgeeks geeksfortest
geeikistest
0
0
Explaination: By running the search query on
contact list for "g" we get: "geeikistest",
"geeksforgeeks" and "geeksfortest".
By running the search query on contact list
for "ge" we get: "geeikistest" "geeksforgeeks"
and "geeksfortest".
By running the search query on contact list
for "gee" we get: "geeikistest" "geeksforgeeks"
and "geeksfortest".
By running the search query on contact list
for "geei" we get: "geeikistest".
No results found for "geeip", so print "0".
No results found for "geeips", so print "0".
Your Task:
Youd do not need to read input or print anything. Your task is to complete the function displayContacts() which takes n, contact[ ] and s as input parameters and returns a list of list of strings for required prefixes. If some prefix has no matching contact return "0" on that list.
Expected Time Complexity: O(|s| * n * max|contact[i]|)
Expected Auxiliary Space: O(n * max|contact[i]|)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/phone-directory4628/1
"Phone directory"
Solve the problem to win points
Given a list of contacts contact[] of length n where each contact is a string which exist in a phone directory and a query string s. The task is to implement a search query for the phone directory. Run a search query for each prefix p of the query string s (i.e. from index 1 to |s|) that prints all the distinct contacts which have the same prefix as p in lexicographical increasing order. Please refer the explanation part for better understanding.
Note: If there is no match between query and contacts, print "0".
Example 1:
Input:
n = 3
contact[] = {"geeikistest", "geeksforgeeks",
"geeksfortest"}
s = "geeips"
Output:
geeikistest geeksforgeeks geeksfortest
geeikistest geeksforgeeks geeksfortest
geeikistest geeksforgeeks geeksfortest
geeikistest
0
0
Explaination: By running the search query on
contact list for "g" we get: "geeikistest",
"geeksforgeeks" and "geeksfortest".
By running the search query on contact list
for "ge" we get: "geeikistest" "geeksforgeeks"
and "geeksfortest".
By running the search query on contact list
for "gee" we get: "geeikistest" "geeksforgeeks"
and "geeksfortest".
By running the search query on contact list
for "geei" we get: "geeikistest".
No results found for "geeip", so print "0".
No results found for "geeips", so print "0".
Your Task:
Youd do not need to read input or print anything. Your task is to complete the function displayContacts() which takes n, contact[ ] and s as input parameters and returns a list of list of strings for required prefixes. If some prefix has no matching contact return "0" on that list.
Expected Time Complexity: O(|s| * n * max|contact[i]|)
Expected Auxiliary Space: O(n * max|contact[i]|)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/phone-directory4628/1
practice.geeksforgeeks.org
Phone directory | Practice | GeeksforGeeks
Given a list of contacts contact[] of length n where each contact is a string which exist in a phone directory and a query string s. The task is to implement a search query for the phone directory. Run a search query for each prefix p of th
π₯6π4π₯°2
Problem Of The Day
"Satisfy the equation"
Solve the problem to win points
Given an array A[ ] of N of integers, find the index of values that satisfy A + B = C + D where A,B,C & D are integers values in the array.
Note: As there may be multiple pairs satisfying the equation return lexicographically smallest order of A, B, C and D and return all as -1 if there are no pairs satisfying the equation.
Example 1:
Input:
N = 7
A[] = {3, 4, 7, 1, 2, 9, 8}
Output:
0 2 3 5
Explanation:
A[0] + A[2] = 3+7 = 10
A[3] + A[5] = 1+9 = 10
Example 2:
Input:
N = 4
A[] = {424, 12, 31, 7}
Output:
-1 -1 -1 -1
Explanation:
There are no pairs satisfying the equation.
Your Task:
You don't need to read input or print anything. Your task is to complete the function satisfyEqn() which takes an Integer N and an array A[] of size N as input and returns a vector of 4 integers denoting A, B, C, and D respectively.
Expected Time Complexity: O(N2*logN2)
Expected Auxiliary Space: O(N2)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/satisfy-the-equation5847/1
"Satisfy the equation"
Solve the problem to win points
Given an array A[ ] of N of integers, find the index of values that satisfy A + B = C + D where A,B,C & D are integers values in the array.
Note: As there may be multiple pairs satisfying the equation return lexicographically smallest order of A, B, C and D and return all as -1 if there are no pairs satisfying the equation.
Example 1:
Input:
N = 7
A[] = {3, 4, 7, 1, 2, 9, 8}
Output:
0 2 3 5
Explanation:
A[0] + A[2] = 3+7 = 10
A[3] + A[5] = 1+9 = 10
Example 2:
Input:
N = 4
A[] = {424, 12, 31, 7}
Output:
-1 -1 -1 -1
Explanation:
There are no pairs satisfying the equation.
Your Task:
You don't need to read input or print anything. Your task is to complete the function satisfyEqn() which takes an Integer N and an array A[] of size N as input and returns a vector of 4 integers denoting A, B, C, and D respectively.
Expected Time Complexity: O(N2*logN2)
Expected Auxiliary Space: O(N2)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/satisfy-the-equation5847/1
practice.geeksforgeeks.org
Satisfy the equation | Practice | GeeksforGeeks
Given an array A[ ] of N of integers, find the index of values that satisfy A + B = C + D where A,B,C & D are integers values in the array.
Note: As there may be multiple pairs satisfying the equation return lexicographically smallest orde
Note: As there may be multiple pairs satisfying the equation return lexicographically smallest orde
π3
Problem Of The Day
"Median in a row-wise sorted Matrix"
Solve the problem to win points
Given a row wise sorted matrix of size R*C where R and C are always odd, find the median of the matrix.
Example 1:
Input:
R = 3, C = 3
M = [[1, 3, 5],
[2, 6, 9],
[3, 6, 9]]
Output: 5
Explanation: Sorting matrix elements gives
us {1,2,3,3,5,6,6,9,9}. Hence, 5 is median.
Example 2:
Input:
R = 3, C = 1
M = [[1], [2], [3]]
Output: 2
Explanation: Sorting matrix elements gives
us {1,2,3}. Hence, 2 is median.
Your Task:
You don't need to read input or print anything. Your task is to complete the function median() which takes the integers R and C along with the 2D matrix as input parameters and returns the median of the matrix.
Expected Time Complexity: O(32 * R * log(C))
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/median-in-a-row-wise-sorted-matrix1527/1
"Median in a row-wise sorted Matrix"
Solve the problem to win points
Given a row wise sorted matrix of size R*C where R and C are always odd, find the median of the matrix.
Example 1:
Input:
R = 3, C = 3
M = [[1, 3, 5],
[2, 6, 9],
[3, 6, 9]]
Output: 5
Explanation: Sorting matrix elements gives
us {1,2,3,3,5,6,6,9,9}. Hence, 5 is median.
Example 2:
Input:
R = 3, C = 1
M = [[1], [2], [3]]
Output: 2
Explanation: Sorting matrix elements gives
us {1,2,3}. Hence, 2 is median.
Your Task:
You don't need to read input or print anything. Your task is to complete the function median() which takes the integers R and C along with the 2D matrix as input parameters and returns the median of the matrix.
Expected Time Complexity: O(32 * R * log(C))
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/median-in-a-row-wise-sorted-matrix1527/1
www.geeksforgeeks.org
Median in a row-wise sorted Matrix | Practice | GeeksforGeeks
Given a row-wise sorted matrix mat[][] where the number of rows and columns is always odd. Return the median of the matrix.
Examples:
Input: mat[][] = [[1, 3, 5], [2, 6, 9], [3, 6, 9]]
Output: 5
Exp
Examples:
Input: mat[][] = [[1, 3, 5], [2, 6, 9], [3, 6, 9]]
Output: 5
Exp
π4π₯2
Must Do DSA Topics day 18
Hashing
Open Addressing:
Like separate chaining, open addressing is a method for handling collisions. In Open Addressing, all elements are stored in the hash table itself. So at any point, the size of the table must be greater than or equal to the total number of keys.
Learn more here : https://bit.ly/3TTV4g1
Double Hashing : Double hashing is a collision resolving technique in Open Addressed Hash tables. Double hashing uses the idea of applying a second hash function to key when a collision occurs.
Learn more here : https://bit.ly/3NnC72y
Load Factor and Rehashing : Rehashing means hashing again. When the load factor increases to more than its pre-defined value (default value of load factor is 0.75), the complexity increases. The size of the array is increased (doubled) and all the values are hashed again and stored in the new double sized array to maintain a low load factor and low complexity.
Learn more here : https://bit.ly/3SRYtub
Hashing
Open Addressing:
Like separate chaining, open addressing is a method for handling collisions. In Open Addressing, all elements are stored in the hash table itself. So at any point, the size of the table must be greater than or equal to the total number of keys.
Learn more here : https://bit.ly/3TTV4g1
Double Hashing : Double hashing is a collision resolving technique in Open Addressed Hash tables. Double hashing uses the idea of applying a second hash function to key when a collision occurs.
Learn more here : https://bit.ly/3NnC72y
Load Factor and Rehashing : Rehashing means hashing again. When the load factor increases to more than its pre-defined value (default value of load factor is 0.75), the complexity increases. The size of the array is increased (doubled) and all the values are hashed again and stored in the new double sized array to maintain a low load factor and low complexity.
Learn more here : https://bit.ly/3SRYtub
π3
Problem Of The Day
"Enemy"
Solve the problem to win points
You live in Geek land. Geek land can be seen as a grid of shape N x M.Their are K enemy at K positions. Each enemy blocks the row and column to which it belongs. You have to find the largest continuous area that is not blocked.No two enemies share the same row or the same column.
Example 1:
Input:
N = 2
M = 2
K = 1
enemy[]={{2,2}}
Output:
1
Explanation:
Since only (1,1) cell is free from the enemy hence answer is 1.
Example 2:
Input:
N = 3
M = 3
K = 1
enemy[]={{3,3}}
Output:
4
Explanation:
The cells (1,1),(1,2) ,(2,1) and (2,2) are free hence answer =4.
Your Task:
You don't need to read input or print anything. Your task is to complete the function largestArea() which takes the size of geek land n,m and a 2-D matrix enemy of size k denoting the coordinates of the enemy's and need to return the largest area that is free.
Expected Time Complexity: O(KlogK)
Expected Auxiliary Space: O(K)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/enemy/1
"Enemy"
Solve the problem to win points
You live in Geek land. Geek land can be seen as a grid of shape N x M.Their are K enemy at K positions. Each enemy blocks the row and column to which it belongs. You have to find the largest continuous area that is not blocked.No two enemies share the same row or the same column.
Example 1:
Input:
N = 2
M = 2
K = 1
enemy[]={{2,2}}
Output:
1
Explanation:
Since only (1,1) cell is free from the enemy hence answer is 1.
Example 2:
Input:
N = 3
M = 3
K = 1
enemy[]={{3,3}}
Output:
4
Explanation:
The cells (1,1),(1,2) ,(2,1) and (2,2) are free hence answer =4.
Your Task:
You don't need to read input or print anything. Your task is to complete the function largestArea() which takes the size of geek land n,m and a 2-D matrix enemy of size k denoting the coordinates of the enemy's and need to return the largest area that is free.
Expected Time Complexity: O(KlogK)
Expected Auxiliary Space: O(K)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/enemy/1
practice.geeksforgeeks.org
Enemy | Practice | GeeksforGeeks
You live in Geek land. Geek land can be seen as a grid of shape N x M.Their are K enemy at K positions. Each enemy blocks the row and column to which it belongs. You have to find the largest continuous area that is not blocked.No
π1
Must Do DSA Topics day 19
Hashing
Print a Binary Tree in Vertical Order : Given a binary tree, print it vertically. The following example illustrates the vertical order traversal.
Learn more here : https://bit.ly/3Uc4oeE
Find whether an array is subset of another array : Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order. It may be assumed that elements in both arrays are distinct.
Examples:
Input: arr1[] = {11, 1, 13, 21, 3, 7},
arr2[] = {11, 3, 7, 1}
Output: arr2[] is a subset of arr1[]
Learn more here : https://bit.ly/3UyW3SP
Union and Intersection of two linked lists: Given two Linked Lists, create union and intersection lists that contain union and intersection of the elements present in the given lists. Order of elements in output lists doesnβt matter.
Learn more : https://bit.ly/3NprUD1
Hashing
Print a Binary Tree in Vertical Order : Given a binary tree, print it vertically. The following example illustrates the vertical order traversal.
Learn more here : https://bit.ly/3Uc4oeE
Find whether an array is subset of another array : Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order. It may be assumed that elements in both arrays are distinct.
Examples:
Input: arr1[] = {11, 1, 13, 21, 3, 7},
arr2[] = {11, 3, 7, 1}
Output: arr2[] is a subset of arr1[]
Learn more here : https://bit.ly/3UyW3SP
Union and Intersection of two linked lists: Given two Linked Lists, create union and intersection lists that contain union and intersection of the elements present in the given lists. Order of elements in output lists doesnβt matter.
Learn more : https://bit.ly/3NprUD1
π1
Problem Of The Day
"Array Removals"
Solve the problem to win points
Given an array arr[] of size N and an integer K. The task is to find the minimum number of elements that should be removed, such that Amax-Amin<=K. After the removal of elements, Amax and Amin is considered among the remaining elements.
Note: Can you solve the probelm without using any extra space and O(N*log(N)) time complexity?
Example 1:
Input: N = 9, K = 4
arr[] = {1,3,4,9,10,11,12,17,20}
Output: 5
Explanation: Remove 1, 3, 4 from beginning
and 17, 20 from the end.
Example 2:
Input: N = 5, K = 2
arr[] = {1, 5, 6, 2, 8}
Output: 3
Explanation: There are multiple ways to
remove elements in this case.
One among them is to remove 5, 6, 8.
The other is to remove 1, 2, 5
Your Task:
You don't need to read input or print anything. Your task is to complete the function removals() which takes the array of integers arr, n and k as parameters and returns an integer, denotes minimum number of elements should be remove to satisfy the condition.
Expected Time Complexity: O(N^2)
Expected Auxiliary Space: O(N^2)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/array-removals/1
"Array Removals"
Solve the problem to win points
Given an array arr[] of size N and an integer K. The task is to find the minimum number of elements that should be removed, such that Amax-Amin<=K. After the removal of elements, Amax and Amin is considered among the remaining elements.
Note: Can you solve the probelm without using any extra space and O(N*log(N)) time complexity?
Example 1:
Input: N = 9, K = 4
arr[] = {1,3,4,9,10,11,12,17,20}
Output: 5
Explanation: Remove 1, 3, 4 from beginning
and 17, 20 from the end.
Example 2:
Input: N = 5, K = 2
arr[] = {1, 5, 6, 2, 8}
Output: 3
Explanation: There are multiple ways to
remove elements in this case.
One among them is to remove 5, 6, 8.
The other is to remove 1, 2, 5
Your Task:
You don't need to read input or print anything. Your task is to complete the function removals() which takes the array of integers arr, n and k as parameters and returns an integer, denotes minimum number of elements should be remove to satisfy the condition.
Expected Time Complexity: O(N^2)
Expected Auxiliary Space: O(N^2)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/array-removals/1
www.geeksforgeeks.org
Array Removals | Practice | GeeksforGeeks
Given an array arr[] of size N and an integer K. The task is to find the minimum number of elements that should be removed, such that Amax-Amin<=K. After the removal of elements, Amax and Amin is considered among the remaining eleme
Must Do DSA Topics day 20
Hashing
Check if a pair exists with given sum in given array : Given an array A[] of n numbers and another number x, the task is to check whether or not there exist two elements in A[] whose sum is exactly x.
Examples:
Input: arr[] = {0, -1, 2, -3, 1}, x= -2
Output: Yes
Learn more : https://bit.ly/3DvTdag
Minimum delete operations to make all elements of array same : Given an array of n elements such that elements may repeat. We can delete any number of elements from the array. The task is to find a minimum number of elements to be deleted from the array to make it equal.
Learn more :
https://bit.ly/3UeGj7m
Minimum operation to make all elements equal in array: Given an array with n positive integers. We need to find the minimum number of operation to make all elements equal. We can perform addition, multiplication, subtraction or division with any element on an array element.
Learn more : https://bit.ly/3fu1Uts
Hashing
Check if a pair exists with given sum in given array : Given an array A[] of n numbers and another number x, the task is to check whether or not there exist two elements in A[] whose sum is exactly x.
Examples:
Input: arr[] = {0, -1, 2, -3, 1}, x= -2
Output: Yes
Learn more : https://bit.ly/3DvTdag
Minimum delete operations to make all elements of array same : Given an array of n elements such that elements may repeat. We can delete any number of elements from the array. The task is to find a minimum number of elements to be deleted from the array to make it equal.
Learn more :
https://bit.ly/3UeGj7m
Minimum operation to make all elements equal in array: Given an array with n positive integers. We need to find the minimum number of operation to make all elements equal. We can perform addition, multiplication, subtraction or division with any element on an array element.
Learn more : https://bit.ly/3fu1Uts
Must Do DSA Topics day 21
Hashing
Maximum distance between two occurrences of same element in array : Given an array with repeated elements, the task is to find the maximum distance between two occurrences of an element.
Input : arr[] = {3, 2, 1, 2, 1, 4, 5, 8, 6, 7, 4, 2}
Output: 10
// maximum distance for 2 is 11-1 = 10
// maximum distance for 1 is 4-2 = 2
// maximum distance for 4 is 10-5 = 5
Learn more : https://bit.ly/3gVEnSz
Count maximum points on same line : Given N point on a 2D plane as pair of (x, y) co-ordinates, we need to find maximum number of point which lie on the same line.
Learn more : https://bit.ly/3WlCL4Z
Check if a given array contains duplicate elements within k distance from each other : Given an unsorted array that may contain duplicates. Also given a number k which is smaller than size of array. Write a function that returns true if array contains duplicates within k distance.
Learn more : https://bit.ly/3h6pvAW
Hashing
Maximum distance between two occurrences of same element in array : Given an array with repeated elements, the task is to find the maximum distance between two occurrences of an element.
Input : arr[] = {3, 2, 1, 2, 1, 4, 5, 8, 6, 7, 4, 2}
Output: 10
// maximum distance for 2 is 11-1 = 10
// maximum distance for 1 is 4-2 = 2
// maximum distance for 4 is 10-5 = 5
Learn more : https://bit.ly/3gVEnSz
Count maximum points on same line : Given N point on a 2D plane as pair of (x, y) co-ordinates, we need to find maximum number of point which lie on the same line.
Learn more : https://bit.ly/3WlCL4Z
Check if a given array contains duplicate elements within k distance from each other : Given an unsorted array that may contain duplicates. Also given a number k which is smaller than size of array. Write a function that returns true if array contains duplicates within k distance.
Learn more : https://bit.ly/3h6pvAW
π1
Problem Of The Day
"Base Equivalence"
Solve the problem to win points
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32.
Example 1:
Input: n = 8, m = 2
Output: Yes
Explanation: Possible in base 3 as 8 in base 3 is 22.
Example 2:
Input: n = 8, m = 3
Output: No
Explanation: Not possible in any base.
Your Task:
You dont need to read input or print anything. Complete the function baseEquiv() which takes n and m as input parameter and returns "Yes" if its possible to represent the number else "No" without quotes..
Expected Time Complexity: O(logN).
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/base-equivalence1022/1
"Base Equivalence"
Solve the problem to win points
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32.
Example 1:
Input: n = 8, m = 2
Output: Yes
Explanation: Possible in base 3 as 8 in base 3 is 22.
Example 2:
Input: n = 8, m = 3
Output: No
Explanation: Not possible in any base.
Your Task:
You dont need to read input or print anything. Complete the function baseEquiv() which takes n and m as input parameter and returns "Yes" if its possible to represent the number else "No" without quotes..
Expected Time Complexity: O(logN).
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/base-equivalence1022/1
practice.geeksforgeeks.org
Base Equivalence | Practice | GeeksforGeeks
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32.
Example 1:
Input: n = 8, m = 2
Output: Yes
Explanation: Poss
Example 1:
Input: n = 8, m = 2
Output: Yes
Explanation: Poss
π4
Problem Of The Day
"Grouping Of Numbers"
Solve the problem to win points
One day Jim came across array arr[] of N numbers. He decided to divide these N numbers into different groups. Each group contains numbers in which sum of any two numbers should not be divisible by an integer K. Print the size of the group containing maximum numbers.
Example 1:
Input:
N = 4, K = 8
arr[] = {1, 7, 2, 6}
Output:
2
Explanation:
The group of numbers which can be formed
are: (1),(2),(7),(6),(1,2),(1,6),(7,2),(7,6).
So,the maximum possible size of the group is 2.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxGroupSize() which takes 2 Integers N, and K and also an array arr[] of N integers as input and returns the maximum group size possible.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(K)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/grouping-of-numbers0015/1
"Grouping Of Numbers"
Solve the problem to win points
One day Jim came across array arr[] of N numbers. He decided to divide these N numbers into different groups. Each group contains numbers in which sum of any two numbers should not be divisible by an integer K. Print the size of the group containing maximum numbers.
Example 1:
Input:
N = 4, K = 8
arr[] = {1, 7, 2, 6}
Output:
2
Explanation:
The group of numbers which can be formed
are: (1),(2),(7),(6),(1,2),(1,6),(7,2),(7,6).
So,the maximum possible size of the group is 2.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxGroupSize() which takes 2 Integers N, and K and also an array arr[] of N integers as input and returns the maximum group size possible.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(K)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/grouping-of-numbers0015/1
practice.geeksforgeeks.org
Grouping Of Numbers | Practice | GeeksforGeeks
One day Jim came across array arr[] of N numbers. He decided to divide these N numbers into different groups. Each group contains numbers in which sum of any two numbers should not be divisible by an integer K. Print the size of the group containing
Must Do DSA Topics day 22
Strings
Function to copy string (Iterative and Recursive) : Given two strings, copy one string to other using recursion. We basically need to write our own recursive version of strcpy in C/C++
Examples: Input : s1 = "hello"
s2 = "geeksforgeeks"
Output : s2 = "hello"
Input : s1 = "geeksforgeeks"
s2 = ""
Output : s2 = "geeksforgeeks"
Learn more : https://bit.ly/3FMU6O8
Check if given String is Pangram or not : Given a string Str. The task is to check if it is Pangram or not.
Examples:
Input: βThe quick brown fox jumps over the lazy dogβ
Output: is a Pangram
Explanation: Contains all the characters from βaβ to βzβ]
Learn more : https://bit.ly/3T6NvRR
Missing characters to make a string Pangram : Pangram is a sentence containing every letter in the English alphabet. Given a string, find all characters that are missing from the string. We need to print output in alphabetic order.
Learn more : https://bit.ly/3heToyV
Strings
Function to copy string (Iterative and Recursive) : Given two strings, copy one string to other using recursion. We basically need to write our own recursive version of strcpy in C/C++
Examples: Input : s1 = "hello"
s2 = "geeksforgeeks"
Output : s2 = "hello"
Input : s1 = "geeksforgeeks"
s2 = ""
Output : s2 = "geeksforgeeks"
Learn more : https://bit.ly/3FMU6O8
Check if given String is Pangram or not : Given a string Str. The task is to check if it is Pangram or not.
Examples:
Input: βThe quick brown fox jumps over the lazy dogβ
Output: is a Pangram
Explanation: Contains all the characters from βaβ to βzβ]
Learn more : https://bit.ly/3T6NvRR
Missing characters to make a string Pangram : Pangram is a sentence containing every letter in the English alphabet. Given a string, find all characters that are missing from the string. We need to print output in alphabetic order.
Learn more : https://bit.ly/3heToyV
π7
Problem Of The Day
"Two numbers with odd occurrences"
Solve the problem to win points
Given an unsorted array, Arr[] of size N and that contains even number of occurrences for all numbers except two numbers. Find the two numbers in decreasing order which has odd occurrences.
Example 1:
Input:
N = 8
Arr = {4, 2, 4, 5, 2, 3, 3, 1}
Output: {5, 1}
Explaination: 5 and 1 have odd occurrences.
Your Task:
You don't need to read input or print anything. Your task is to complete the function twoOddNum() which takes the array Arr[] and its size N as input parameters and returns the two numbers in decreasing order which have odd occurrences.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/two-numbers-with-odd-occurrences5846/1
"Two numbers with odd occurrences"
Solve the problem to win points
Given an unsorted array, Arr[] of size N and that contains even number of occurrences for all numbers except two numbers. Find the two numbers in decreasing order which has odd occurrences.
Example 1:
Input:
N = 8
Arr = {4, 2, 4, 5, 2, 3, 3, 1}
Output: {5, 1}
Explaination: 5 and 1 have odd occurrences.
Your Task:
You don't need to read input or print anything. Your task is to complete the function twoOddNum() which takes the array Arr[] and its size N as input parameters and returns the two numbers in decreasing order which have odd occurrences.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/two-numbers-with-odd-occurrences5846/1
www.geeksforgeeks.org
Two numbers with odd occurrences | Practice | GeeksforGeeks
Given an unsorted array, Arr[] of size N and that contains even number of occurrences for all numbers except two numbers. Find the two numbers in decreasing order which has odd occurrences.Example 1:
Input:
N = 8
Arr = {4, 2, 4, 5, 2, 3, 3, 1}
O
Input:
N = 8
Arr = {4, 2, 4, 5, 2, 3, 3, 1}
O
π4π₯1
Problem Of The Day
"Minimum sum partition"
Solve the problem to win points
Given an array arr of size n containing non-negative integers, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum and find the minimum difference
Example 1:
Input: N = 4, arr[] = {1, 6, 11, 5}
Output: 1
Explanation:
Subset1 = {1, 5, 6}, sum of Subset1 = 12
Subset2 = {11}, sum of Subset2 = 11
Your Task:
You don't need to read input or print anything. Complete the function minDifference() which takes N and array arr as input parameters and returns the integer value
Expected Time Complexity: O(N*|sum of array elements|)
Expected Auxiliary Space: O(N*|sum of array elements|)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/minimum-sum-partition3317/1
"Minimum sum partition"
Solve the problem to win points
Given an array arr of size n containing non-negative integers, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum and find the minimum difference
Example 1:
Input: N = 4, arr[] = {1, 6, 11, 5}
Output: 1
Explanation:
Subset1 = {1, 5, 6}, sum of Subset1 = 12
Subset2 = {11}, sum of Subset2 = 11
Your Task:
You don't need to read input or print anything. Complete the function minDifference() which takes N and array arr as input parameters and returns the integer value
Expected Time Complexity: O(N*|sum of array elements|)
Expected Auxiliary Space: O(N*|sum of array elements|)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/minimum-sum-partition3317/1
practice.geeksforgeeks.org
Minimum sum partition | Practice | GeeksforGeeks
Given an array arr of size n containing non-negative integers, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum and find the minimum difference
Example 1:
Input: N =
Example 1:
Input: N =
π3π2π₯1
Problem Of The Day
"Jumping Numbers"
Solve the problem to win points
Given a positive number X. Find the largest Jumping Number which is smaller than or equal to X.
Jumping Number: A number is called Jumping Number if all adjacent digits in it differ by only 1. All single-digit numbers are considered as Jumping Numbers. For example 7, 8987 and 4343456 are Jumping numbers but 796, 677 and 89098 are not.
Example 1:
Input:
X = 10
Output:
10
Explanation:
10 is the largest Jumping Number
possible for X = 10.
Your Task:
You don't need to read input or print anything. Your task is to complete the function jumpingNums() which takes an Integer X as input and returns the largest Jumping Number less than or equal to X.
Expected Time Complexity: O(k), where k is no of jumping numbers
Expected Auxiliary Space: O(k), where k is no of jumping numbers
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/jumping-numbers3805/1
"Jumping Numbers"
Solve the problem to win points
Given a positive number X. Find the largest Jumping Number which is smaller than or equal to X.
Jumping Number: A number is called Jumping Number if all adjacent digits in it differ by only 1. All single-digit numbers are considered as Jumping Numbers. For example 7, 8987 and 4343456 are Jumping numbers but 796, 677 and 89098 are not.
Example 1:
Input:
X = 10
Output:
10
Explanation:
10 is the largest Jumping Number
possible for X = 10.
Your Task:
You don't need to read input or print anything. Your task is to complete the function jumpingNums() which takes an Integer X as input and returns the largest Jumping Number less than or equal to X.
Expected Time Complexity: O(k), where k is no of jumping numbers
Expected Auxiliary Space: O(k), where k is no of jumping numbers
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/jumping-numbers3805/1
www.geeksforgeeks.org
Jumping Numbers | Practice | GeeksforGeeks
Given a positive number X. Find the largest Jumping Number which is smaller than or equal to X.
Jumping Number: A number is called Jumping Number if all adjacent digits in it differ by only 1. All single-digit numbers are considered as Jumping
Jumping Number: A number is called Jumping Number if all adjacent digits in it differ by only 1. All single-digit numbers are considered as Jumping
Must Do DSA Topics day 23
Strings
Check if a string is Pangrammatic Lipogram : A pangrammatic lipogram is a text that uses every letter of the alphabet except one. For example, βThe quick brown fox jumped over the lazy dogβ omits the letter S, which the usual pangram includes by using the word jumps.
Given a string, our task is to check whether this string is a pangrammatic lipogram or not?
Learn more : http://bit.ly/3EjrGdy
Removing punctuations from a given string : Given a string, remove the punctuation from the string if the given character is a punctuation character, as classified by the current C locale. The default C locale classifies these characters as punctuation:
! " # $ % & ' ( ) * + , - . /
Learn more : http://bit.ly/3G2lAzs
Rearrange characters in a String such that no two adjacent characters are same : Given a string with lowercase repeated characters, the task is to rearrange characters in a string so that no two adjacent characters are the same.
Learn more : http://bit.ly/3UrNZmU
Strings
Check if a string is Pangrammatic Lipogram : A pangrammatic lipogram is a text that uses every letter of the alphabet except one. For example, βThe quick brown fox jumped over the lazy dogβ omits the letter S, which the usual pangram includes by using the word jumps.
Given a string, our task is to check whether this string is a pangrammatic lipogram or not?
Learn more : http://bit.ly/3EjrGdy
Removing punctuations from a given string : Given a string, remove the punctuation from the string if the given character is a punctuation character, as classified by the current C locale. The default C locale classifies these characters as punctuation:
! " # $ % & ' ( ) * + , - . /
Learn more : http://bit.ly/3G2lAzs
Rearrange characters in a String such that no two adjacent characters are same : Given a string with lowercase repeated characters, the task is to rearrange characters in a string so that no two adjacent characters are the same.
Learn more : http://bit.ly/3UrNZmU
π2
Problem Of The Day
"Primes sum"
Solve the problem to win points
Given a number N. Find if it can be expressed as sum of two prime numbers.
Example 1:
Input: N = 34
Output: "Yes"
Explanation: 34 can be expressed as
sum of two prime numbers.
Your Task:
You dont need to read input or print anything. Complete the function isSumOfTwo() which takes N as input parameter and returns "Yes" if can be expressed as sum of two prime numbers. else return "No".
Expected Time Complexity: O(N*sqrt(N))
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/primes-sum5827/1
"Primes sum"
Solve the problem to win points
Given a number N. Find if it can be expressed as sum of two prime numbers.
Example 1:
Input: N = 34
Output: "Yes"
Explanation: 34 can be expressed as
sum of two prime numbers.
Your Task:
You dont need to read input or print anything. Complete the function isSumOfTwo() which takes N as input parameter and returns "Yes" if can be expressed as sum of two prime numbers. else return "No".
Expected Time Complexity: O(N*sqrt(N))
Expected Auxiliary Space: O(1)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/primes-sum5827/1
practice.geeksforgeeks.org
Primes sum | Practice | GeeksforGeeks
Given a number N. Find if it can be expressed as sum of two prime numbers.
Example 1:
Input: N = 34
Output: "Yes"
Explanation: 34 can be expressed as
sum of two prime numbers.
Example 2:
Input: N = 23
Outpu
Example 1:
Input: N = 34
Output: "Yes"
Explanation: 34 can be expressed as
sum of two prime numbers.
Example 2:
Input: N = 23
Outpu
π1π1
Problem Of The Day
"Maximum Sub-String after at most K changes"
Solve the problem to win points
We have a string s of length n, which contains only UPPERCASE characters and we have a number k (always less than n). We can make at most k changes in our string. In one change, you can replace any s[i] (0<= i < n) with any uppercase character (from 'A' to 'Z'). After k changes, find the maximum possible length of the sub-string which have all same characters.
Example 1:
Input: s = "ABAB", k = 2
Output: 4
Explanation: Change 2 'B' into 'A'.
Now s = "AAAA"
Your Task:
You don't need to read or print anything. Your task is to complete the function characterReplacement() which takes s and k as input parameters and returns the maximum length of sub-string after doing k changes.
Expected Time Complexity: O(n)
Expected Space Complexity: O(26)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/maximum-sub-string-after-at-most-k-changes3220/1
"Maximum Sub-String after at most K changes"
Solve the problem to win points
We have a string s of length n, which contains only UPPERCASE characters and we have a number k (always less than n). We can make at most k changes in our string. In one change, you can replace any s[i] (0<= i < n) with any uppercase character (from 'A' to 'Z'). After k changes, find the maximum possible length of the sub-string which have all same characters.
Example 1:
Input: s = "ABAB", k = 2
Output: 4
Explanation: Change 2 'B' into 'A'.
Now s = "AAAA"
Your Task:
You don't need to read or print anything. Your task is to complete the function characterReplacement() which takes s and k as input parameters and returns the maximum length of sub-string after doing k changes.
Expected Time Complexity: O(n)
Expected Space Complexity: O(26)
Solve the problem and submit your answers here: https://practice.geeksforgeeks.org/problems/maximum-sub-string-after-at-most-k-changes3220/1
practice.geeksforgeeks.org
Maximum Sub-String after at most K changes | Practice | GeeksforGeeks
We have a string s of length n, which contains only UPPERCASE characters and we have a number k (always less than n). We can make at most k changes in our string. In one change, you can replace any s[i] (0<= i < n) with any
π3β€1π1
Problem Of The Day
"Find patterns"
Solve the problem to win points
Given two strings S and W. Find the number of times W appears as a subsequence of string S where every character of string S can be included in forming at most one subsequence.
Example:
Input:
S = "abcdrtbwerrcokokokd"
W = "bcd"
Output:
2
Explanation:
The two subsequences of string W are
{ S1 , S2 , S3 } and { S6 , S11 , S18 }
(Assuming 0- based indexing).
Your Task:
You don't need to read input or print anything. Your task is to complete the function numberOfSubsequences() which takes the string S and string W as input parameters and returns the number of subsequences of string W in string S.
Expected Time Complexity: O(N2)
Expected Auxiliary Space: O(N)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/find-patterns0606/1
"Find patterns"
Solve the problem to win points
Given two strings S and W. Find the number of times W appears as a subsequence of string S where every character of string S can be included in forming at most one subsequence.
Example:
Input:
S = "abcdrtbwerrcokokokd"
W = "bcd"
Output:
2
Explanation:
The two subsequences of string W are
{ S1 , S2 , S3 } and { S6 , S11 , S18 }
(Assuming 0- based indexing).
Your Task:
You don't need to read input or print anything. Your task is to complete the function numberOfSubsequences() which takes the string S and string W as input parameters and returns the number of subsequences of string W in string S.
Expected Time Complexity: O(N2)
Expected Auxiliary Space: O(N)
Solve the problem and submit your answers here : https://practice.geeksforgeeks.org/problems/find-patterns0606/1
practice.geeksforgeeks.org
Find patterns | Practice | GeeksforGeeks
Given two strings S and W. Find the number of times W appears as a subsequence of string S where every character of string S can be included in forming at most one subsequence.
Example 1:
Input:
S = "abcdrtbwe
Example 1:
Input:
S = "abcdrtbwe