Knock! Knock!π
The New Year Party goes on with upto 25% off on your favourite courses and much more!π
Click on the following for more details - https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
The New Year Party goes on with upto 25% off on your favourite courses and much more!π
Click on the following for more details - https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
This media is not supported in your browser
VIEW IN TELEGRAM
Get ready for some DSA lectures with Mr. Sandeep Jain (Mentor of DSA Self Paced , CEO & Founder) as he will join you LIVE for the next 3 months! So if you were looking for a reason to join, nowβs the time!
You can attend his LIVE community classes by enrolling in any one of the 2 courses-
DSA Self Paced: https://practice.geeksforgeeks.org/courses/dsa-self-paced
Complete Interview Preparation: https://practice.geeksforgeeks.org/courses/complete-interview-preparation
ββββββββββββββ-
So start today! π―
You can attend his LIVE community classes by enrolling in any one of the 2 courses-
DSA Self Paced: https://practice.geeksforgeeks.org/courses/dsa-self-paced
Complete Interview Preparation: https://practice.geeksforgeeks.org/courses/complete-interview-preparation
ββββββββββββββ-
So start today! π―
π4π€1
Problem Of The Day
"Absolute difference divisible by K"
Solve the problem to win points
Given an array of integers of size n and an integer k, find all the pairs in the array whose absolute difference is divisible by k.
Example 1:
Input:
n = 3
arr[] = {3, 7, 11}
k = 4
Output:
3
Explanation:
(11-3) = 8 is divisible by 4
(11-7) = 4 is divisible by 4
(7-3) = 4 is divisible by 4
Example 2:
Input:
n = 4
arr[] = {1, 2, 3, 4}
k = 2
Output :
2
Explanation:
Valid pairs are (1,3), and (2,4).
Your Task:
You don't need to read input or print anything. Your task is to complete the function countPairs() which takes integers n, array arr[ ], integer k as input parameters and returns the number of pairs whose absolute difference is divisible by k.
Note: The answer may be large so use 64-bit integer.
Expected Time Complexity: O(n + k)
Expected Auxiliary Space: O(k)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/e0059183c88ab680b2f73f7d809fb8056fe9dc43/1
Powered by hirist.com
"Absolute difference divisible by K"
Solve the problem to win points
Given an array of integers of size n and an integer k, find all the pairs in the array whose absolute difference is divisible by k.
Example 1:
Input:
n = 3
arr[] = {3, 7, 11}
k = 4
Output:
3
Explanation:
(11-3) = 8 is divisible by 4
(11-7) = 4 is divisible by 4
(7-3) = 4 is divisible by 4
Example 2:
Input:
n = 4
arr[] = {1, 2, 3, 4}
k = 2
Output :
2
Explanation:
Valid pairs are (1,3), and (2,4).
Your Task:
You don't need to read input or print anything. Your task is to complete the function countPairs() which takes integers n, array arr[ ], integer k as input parameters and returns the number of pairs whose absolute difference is divisible by k.
Note: The answer may be large so use 64-bit integer.
Expected Time Complexity: O(n + k)
Expected Auxiliary Space: O(k)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/e0059183c88ab680b2f73f7d809fb8056fe9dc43/1
Powered by hirist.com
practice.geeksforgeeks.org
Absolute difference divisible by K | Practice | GeeksforGeeks
Given an array of integers of size n and an integer k, find all the pairs in the array whose absolute difference is divisible by k.
Example 1:
Input:
n = 3
arr[] = {3, 7, 11}
k = 4
Output:
3
Explanation:
(11-3) = 8 is di
Example 1:
Input:
n = 3
arr[] = {3, 7, 11}
k = 4
Output:
3
Explanation:
(11-3) = 8 is di
π5
Problem Of The Day
"Last modified ball"
Solve the problem to win points
Samwell laid out N bowls in a straight line and put a few marbles randomly in each bowl, ith bowl has A[i] marbles. A bowl can never have more than 9 marbles at a time. A bowl can have zero marbles. Now Samwells friend adds one more marble to the last bowl, after this addition all the bowls must still be aligned with the rules mentioned above. Adding a marble follows the same rules as of addition with carryover. You are given the initial list of the number of marbles in each bowl find the position of the bowl which was last modified. It is guaranteed that there is at least one bowl which has at least one space left.
Note: Consider one-based indexing.
Input:
N = 4
A[] = {3, 1, 4, 5}
Output:
4
Explanation:
The last bowl has 5 marbels, we can just
add the marbel here.
Example 2:
Input:
N = 3
A[] = {1, 9, 9}
Output:
1
Explanation:
When we add the marbel to last bowl we
have to move one marbel to 2nd bowl,
to add the marbel in 2nd bowl we have
to move one marbel to 1st bowl.
Hence the last modified bowl is 1.
Your Task:
You don't need to read input or print anything. Your task is to complete the function solve( ) which takes N and A[ ] as input parameters and returns the position of the last modified bowl.
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/33af95e5935f1f2a0c3f5083c4b9d0db68e97bd4/1
Powered by hirist.com
"Last modified ball"
Solve the problem to win points
Samwell laid out N bowls in a straight line and put a few marbles randomly in each bowl, ith bowl has A[i] marbles. A bowl can never have more than 9 marbles at a time. A bowl can have zero marbles. Now Samwells friend adds one more marble to the last bowl, after this addition all the bowls must still be aligned with the rules mentioned above. Adding a marble follows the same rules as of addition with carryover. You are given the initial list of the number of marbles in each bowl find the position of the bowl which was last modified. It is guaranteed that there is at least one bowl which has at least one space left.
Note: Consider one-based indexing.
Input:
N = 4
A[] = {3, 1, 4, 5}
Output:
4
Explanation:
The last bowl has 5 marbels, we can just
add the marbel here.
Example 2:
Input:
N = 3
A[] = {1, 9, 9}
Output:
1
Explanation:
When we add the marbel to last bowl we
have to move one marbel to 2nd bowl,
to add the marbel in 2nd bowl we have
to move one marbel to 1st bowl.
Hence the last modified bowl is 1.
Your Task:
You don't need to read input or print anything. Your task is to complete the function solve( ) which takes N and A[ ] as input parameters and returns the position of the last modified bowl.
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/33af95e5935f1f2a0c3f5083c4b9d0db68e97bd4/1
Powered by hirist.com
practice.geeksforgeeks.org
Last modified ball | Practice | GeeksforGeeks
Samwell laid out N bowls in a straight line and put a few marbles randomly in each bowl, ith bowl has A[i] marbles. A bowl can never have more than 9 marbles at a time. A bowl can have zero marbles. Now Samwells friend adds one more ma
π2
Must Do DSA Topics Day 85
Backtracking
Introduction to Backtracking β Data Structure and Algorithm Tutorials : Backtracking is an algorithmic technique for solving problems recursively by trying to build a solution incrementally, one piece at a time, removing those solutions that fail to satisfy the constraints of the problem at any point in time.
Learn more : https://bit.ly/3GsupRI
Backtracking Algorithms : Backtracking can be defined as a general algorithmic technique that considers searching every possible combination in order to solve a computational problem.
Learn more : https://bit.ly/3GZl3yF
Word Break Problem using Backtracking : Given a valid sentence without any spaces between the words and a dictionary of valid English words, find all possible ways to break the sentence into individual dictionary words.
Learn more : https://bit.ly/3CwcUPe
Backtracking
Introduction to Backtracking β Data Structure and Algorithm Tutorials : Backtracking is an algorithmic technique for solving problems recursively by trying to build a solution incrementally, one piece at a time, removing those solutions that fail to satisfy the constraints of the problem at any point in time.
Learn more : https://bit.ly/3GsupRI
Backtracking Algorithms : Backtracking can be defined as a general algorithmic technique that considers searching every possible combination in order to solve a computational problem.
Learn more : https://bit.ly/3GZl3yF
Word Break Problem using Backtracking : Given a valid sentence without any spaces between the words and a dictionary of valid English words, find all possible ways to break the sentence into individual dictionary words.
Learn more : https://bit.ly/3CwcUPe
Resolution Days 2023 are keeping the spirit of skills up with upto 25% off on your favourite courses.
Today's special offer includes GFG Premium Plus' subscription worth INR 2000 for free.
For more details, click on the following link- https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
Today's special offer includes GFG Premium Plus' subscription worth INR 2000 for free.
For more details, click on the following link- https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
π1
π¨Job Alert π¨
QUOLAM BUSINESS is hiring for Node JS Developer role in Mahape, Navi Mumbai.
Get more details in the following link and also share the opportunity with your friends - https://practice.geeksforgeeks.org/jobs/Quolam-Nodejs
QUOLAM BUSINESS is hiring for Node JS Developer role in Mahape, Navi Mumbai.
Get more details in the following link and also share the opportunity with your friends - https://practice.geeksforgeeks.org/jobs/Quolam-Nodejs
π1
Problem Of The Day
"Transform to Sum Tree"
Solve the problem to win points
Given a Binary Tree of size N , where each node can have positive or negative values. Convert this to a tree where value of each node will be the sum of the values of all the nodes in left and right sub trees of the original tree. The values of leaf nodes are changed to 0.
Note: You have to modify the given tree in-place.
Example 1:
Input:
10
/ \
-2 6
/ \ / \
8 -4 7 5
Output:
20
/ \
4 12
/ \ / \
0 0 0 0
Explanation:
(4-2+12+6)
/ \
(8-4) (7+5)
/ \ / \
0 0 0 0
Example 2:
Input:
10
/ \
-2 6
/ \ / \
8 -4 7 5
/ \ / \ / \ / \
2 -2 3 -5 9 -8 2 8
Output:
29
/ \
2 23
/ \ / \
0 -2 1 10
/ \ / \ / \ / \
0 0 0 0 0 0 0 0
Explanation:
(2+6+8-4+7+5+2-2+3-5+9-8+2+8)
/ \
(8-4+2-2+3-5) (7+5+9-8+2+8)
/ \ / \
(2-2) (3-5) (9-8) (2+8)
/ \ / \ / \ / \
0 0 0 0 0 0 0 0
Your Task:
You dont need to read input or print anything. Complete the function toSumTree() which takes root node as input parameter and modifies the given tree in-place.
Note: If you click on Compile and Test the output will be the in-order traversal of the modified tree.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(height of tree)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/d7e0ce338b11f0be36877d9c35cc8dfad6636957/1
Powered by hirist.com
"Transform to Sum Tree"
Solve the problem to win points
Given a Binary Tree of size N , where each node can have positive or negative values. Convert this to a tree where value of each node will be the sum of the values of all the nodes in left and right sub trees of the original tree. The values of leaf nodes are changed to 0.
Note: You have to modify the given tree in-place.
Example 1:
Input:
10
/ \
-2 6
/ \ / \
8 -4 7 5
Output:
20
/ \
4 12
/ \ / \
0 0 0 0
Explanation:
(4-2+12+6)
/ \
(8-4) (7+5)
/ \ / \
0 0 0 0
Example 2:
Input:
10
/ \
-2 6
/ \ / \
8 -4 7 5
/ \ / \ / \ / \
2 -2 3 -5 9 -8 2 8
Output:
29
/ \
2 23
/ \ / \
0 -2 1 10
/ \ / \ / \ / \
0 0 0 0 0 0 0 0
Explanation:
(2+6+8-4+7+5+2-2+3-5+9-8+2+8)
/ \
(8-4+2-2+3-5) (7+5+9-8+2+8)
/ \ / \
(2-2) (3-5) (9-8) (2+8)
/ \ / \ / \ / \
0 0 0 0 0 0 0 0
Your Task:
You dont need to read input or print anything. Complete the function toSumTree() which takes root node as input parameter and modifies the given tree in-place.
Note: If you click on Compile and Test the output will be the in-order traversal of the modified tree.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(height of tree)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/d7e0ce338b11f0be36877d9c35cc8dfad6636957/1
Powered by hirist.com
practice.geeksforgeeks.org
Transform to Sum Tree | Practice | GeeksforGeeks
Given a Binary Tree of size N , where each node can have positive or negative values. Convert this to a tree where value of each node will be the sum of the values of all the nodes in left and right sub trees of the original tree. The values of leaf
π2
Must Do DSA Topics Day 86
Backtracking
Difference between Backtracking and Branch-N-Bound technique : Algorithms are the methodical sequence of steps which are defined to solve complex problems. In this article, we will see the difference between two such algorithms which are backtracking and branch and bound technique.
Learn more : https://bit.ly/3QrZGc8
m Coloring Problem | Backtracking-5 : Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with the same color.
Learn more : https://bit.ly/3GtLPO2
Travelling Salesman Problem implementation using BackTracking : Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns back to the starting point.
Learn more : https://bit.ly/3GqwzBz
Backtracking
Difference between Backtracking and Branch-N-Bound technique : Algorithms are the methodical sequence of steps which are defined to solve complex problems. In this article, we will see the difference between two such algorithms which are backtracking and branch and bound technique.
Learn more : https://bit.ly/3QrZGc8
m Coloring Problem | Backtracking-5 : Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent vertices of the graph are colored with the same color.
Learn more : https://bit.ly/3GtLPO2
Travelling Salesman Problem implementation using BackTracking : Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns back to the starting point.
Learn more : https://bit.ly/3GqwzBz
π1
Tik! Tik! Tik!β±οΈ
Last Day Today!!!π
It's the last day of the Resolution Days sale, 2023.
Hurry up and avail upto 25% off on your favourite courses.
Click here for more details - https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
Last Day Today!!!π
It's the last day of the Resolution Days sale, 2023.
Hurry up and avail upto 25% off on your favourite courses.
Click here for more details - https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
Problem Of The Day
"Make array elements unique"
Solve the problem to win points
Given an array arr[ ] of N elements, your task is to find the minimum number of increment operations required to make all the elements of the array unique. ie- no value in the array should occur more than once. In an operation a value can be incremented by 1 only.
Example 1:
Input:
N = 3
arr[] = {1, 2, 2}
Output:
1
Explanation:
If we increase arr[2] by 1 then the resulting
array becomes {1, 2, 3} and has all unique values.
Hence, the answer is 1 in this case.
Example 2:
Input:
N = 4
arr[] = {1, 1, 2, 3}
Output:
3
Explanation:
If we increase arr[0] by 3, then all array
elements will be unique. Hence, the answer
is 3 in this case.
Your Task:
You dont need to read input or print anything. Complete the function minIncrements() which takes the array arr[ ] and its size N as the input parameters, and returns the minimum increment operations required to make all elements of the array unique.
Expected Time Complexity: O(N*log(N))
Expected Auxiliary Space: O(1)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/6e63df6d2ebdf6408a9b364128bb1123b5b13450/1
Powered by hirist.com
"Make array elements unique"
Solve the problem to win points
Given an array arr[ ] of N elements, your task is to find the minimum number of increment operations required to make all the elements of the array unique. ie- no value in the array should occur more than once. In an operation a value can be incremented by 1 only.
Example 1:
Input:
N = 3
arr[] = {1, 2, 2}
Output:
1
Explanation:
If we increase arr[2] by 1 then the resulting
array becomes {1, 2, 3} and has all unique values.
Hence, the answer is 1 in this case.
Example 2:
Input:
N = 4
arr[] = {1, 1, 2, 3}
Output:
3
Explanation:
If we increase arr[0] by 3, then all array
elements will be unique. Hence, the answer
is 3 in this case.
Your Task:
You dont need to read input or print anything. Complete the function minIncrements() which takes the array arr[ ] and its size N as the input parameters, and returns the minimum increment operations required to make all elements of the array unique.
Expected Time Complexity: O(N*log(N))
Expected Auxiliary Space: O(1)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/6e63df6d2ebdf6408a9b364128bb1123b5b13450/1
Powered by hirist.com
practice.geeksforgeeks.org
Make array elements unique | Practice | GeeksforGeeks
Given an array arr[ ] of N elements, your task is to find the minimum number of increment operations required to make all the elements of the array unique. ie- no value in the array should occur more than once. In an operation a value can b
π2
Must Do DSA Topics Day 87
Backtracking
Rat in a Maze | Backtracking using Stack : A Maze is given as N*M binary matrix of blocks and there is a rat initially at (0, 0) ie. maze[0][0] and the rat wants to eat food which is present at some given block in the maze (fx, fy).
Learn more : https://bit.ly/3WYtEaa
Perl | Backtracking in Regular Expression : In Perl, a Regular expression(a.k.a regexes or regexps or REs) is a way of describing a set of strings without having to list all strings in your program or simply we can say that it is a sequence of characters that are used for pattern matching.
Learn more : https://bit.ly/3k2eORn
C/C++ Backtracking Programs : Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that βworksβ. Problems that are typically solved using the backtracking technique have the following property in common.
Learn more : https://bit.ly/3X3hEUY
Backtracking
Rat in a Maze | Backtracking using Stack : A Maze is given as N*M binary matrix of blocks and there is a rat initially at (0, 0) ie. maze[0][0] and the rat wants to eat food which is present at some given block in the maze (fx, fy).
Learn more : https://bit.ly/3WYtEaa
Perl | Backtracking in Regular Expression : In Perl, a Regular expression(a.k.a regexes or regexps or REs) is a way of describing a set of strings without having to list all strings in your program or simply we can say that it is a sequence of characters that are used for pattern matching.
Learn more : https://bit.ly/3k2eORn
C/C++ Backtracking Programs : Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that βworksβ. Problems that are typically solved using the backtracking technique have the following property in common.
Learn more : https://bit.ly/3X3hEUY
Problem Of The Day
"Minimize the sum"
Solve the problem to win points
You are given N elements, you can remove any two elements from the list, note their sum, and add the sum to the list. Repeat these steps while there is more than a single element in the list. The task is to minimize the sum of these chosen sums.
Example 1:
Input:
N = 4
arr[] = {1, 4, 7, 10}
Output:
39
Explanation:
Choose 1 and 4, Sum = 1 + 4 = 5.
arr[] = {5, 7, 10}
Choose 5 and 7, Sum = 5 + (5 + 7) = 17.
arr[] = {12, 10}
Choose 12 and 10, Sum = 17 + (12 + 10) = 39.
arr[] = {22}
Example 2:
Input:
N = 5
arr[] = {1, 3, 7, 5, 6}
Output:
48
Your Task:
You don't need to read input or print anything. The task is to complete the function minimizeSum() which takes N as size of arr array and a arr array. Your task is to minimize the sum of these chosen sums and return it.
Expected Time Complexity: O(N * log(N))
Expected Auxiliary Space: O(N)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/86e609332c9ef4f6b8aa79db11a6c0808c4a1bca/1
Powered by hirist.com
"Minimize the sum"
Solve the problem to win points
You are given N elements, you can remove any two elements from the list, note their sum, and add the sum to the list. Repeat these steps while there is more than a single element in the list. The task is to minimize the sum of these chosen sums.
Example 1:
Input:
N = 4
arr[] = {1, 4, 7, 10}
Output:
39
Explanation:
Choose 1 and 4, Sum = 1 + 4 = 5.
arr[] = {5, 7, 10}
Choose 5 and 7, Sum = 5 + (5 + 7) = 17.
arr[] = {12, 10}
Choose 12 and 10, Sum = 17 + (12 + 10) = 39.
arr[] = {22}
Example 2:
Input:
N = 5
arr[] = {1, 3, 7, 5, 6}
Output:
48
Your Task:
You don't need to read input or print anything. The task is to complete the function minimizeSum() which takes N as size of arr array and a arr array. Your task is to minimize the sum of these chosen sums and return it.
Expected Time Complexity: O(N * log(N))
Expected Auxiliary Space: O(N)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/86e609332c9ef4f6b8aa79db11a6c0808c4a1bca/1
Powered by hirist.com
practice.geeksforgeeks.org
Minimize the sum | Practice | GeeksforGeeks
You are given N elements, you can remove any two elements from the list, note their sum, and add the sum to the list. Repeat these steps while there is more than a single element in the list. The task is to minimize the sum of these chosen
Must Do DSA Topics Day 88
Backtracking
Split a string into maximum number of unique substrings : Given string str, the task is to split the string into the maximum number of unique substrings possible and print their count.
Learn more : https://bit.ly/3keY7Cc
Print all possible ways to split an array into K subsets : Given an array arr[] of size N and an integer K, the task is to print all possible ways to split the given array into K subsets.
Learn more : https://bit.ly/3X2qIt6
Print all root to leaf paths of an N-ary tree : Given an N-Ary tree, the task is to print all root to leaf paths of the given N-ary Tree.
Learn more : https://bit.ly/3X8Iyee
Backtracking
Split a string into maximum number of unique substrings : Given string str, the task is to split the string into the maximum number of unique substrings possible and print their count.
Learn more : https://bit.ly/3keY7Cc
Print all possible ways to split an array into K subsets : Given an array arr[] of size N and an integer K, the task is to print all possible ways to split the given array into K subsets.
Learn more : https://bit.ly/3X2qIt6
Print all root to leaf paths of an N-ary tree : Given an N-Ary tree, the task is to print all root to leaf paths of the given N-ary Tree.
Learn more : https://bit.ly/3X8Iyee
π¨Job Alertπ¨
Akash Educational Services is hiring Senior Salesforce Developer in Gurgaon and Bengalore.
Interesting candidates can apply via the following link and share the opportunity with your friends - https://practice.geeksforgeeks.org/jobs/AkashByjus_salesforcedev
Akash Educational Services is hiring Senior Salesforce Developer in Gurgaon and Bengalore.
Interesting candidates can apply via the following link and share the opportunity with your friends - https://practice.geeksforgeeks.org/jobs/AkashByjus_salesforcedev
Problem Of The Day
"Count Lucky Permutations"
Solve the problem to win points
You are given an array arr[ ] of integers having N elements and a non-weighted undirected graph having N nodes and M edges. The details of each edge in the graph is given to you in the form of list of list.
Your task is to find the number of lucky permutations of the given array.
An array permutation is said to be lucky if for every node Vi [1 < i < N-1] in the array there exists an edge between the nodes Vi and Vi+1 in the given graph.
Example 1:
Input:
N = 3, M = 2
arr = {1, 2, 3}
graph = {{3, 1}, {1, 2}}
Output:
2
Explanation:
All possible permutations of the
array are as follows-
{1,2,3}: There is an edge between 1 and
2 in the graph but not betwen 2 and 3.
{2,1,3}: There is an edge between (2,1)
and (1,3) in the graph.
{3,1,2}: There is an edge between (3,1)
and (1,2) in the graph.
Out of the 3 possible permutations,
2 are lucky. Therefore, answer is 2.
Example 2:
Input:
n = 2, m = 1
arr = {1, 1}
graph = {{1, 2}}
Output :
0
Explanation:
There is no lucky permutation in the
given graph.
Your Task:
You don't need to read input or print anything. Your task is to complete the function luckyPermutations() which takes the two integers N and M, an array arr[ ] and a list of lists named graph of size M as input parameters and returns the count of lucky permutations.
Expected Time Complexity: O(N2*2N)
Expected Auxiliary Space: O(N*2N)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/e9e2da3de3eb35679ca7e17b752ae877635f1a26/1
Powered by hirist.com
"Count Lucky Permutations"
Solve the problem to win points
You are given an array arr[ ] of integers having N elements and a non-weighted undirected graph having N nodes and M edges. The details of each edge in the graph is given to you in the form of list of list.
Your task is to find the number of lucky permutations of the given array.
An array permutation is said to be lucky if for every node Vi [1 < i < N-1] in the array there exists an edge between the nodes Vi and Vi+1 in the given graph.
Example 1:
Input:
N = 3, M = 2
arr = {1, 2, 3}
graph = {{3, 1}, {1, 2}}
Output:
2
Explanation:
All possible permutations of the
array are as follows-
{1,2,3}: There is an edge between 1 and
2 in the graph but not betwen 2 and 3.
{2,1,3}: There is an edge between (2,1)
and (1,3) in the graph.
{3,1,2}: There is an edge between (3,1)
and (1,2) in the graph.
Out of the 3 possible permutations,
2 are lucky. Therefore, answer is 2.
Example 2:
Input:
n = 2, m = 1
arr = {1, 1}
graph = {{1, 2}}
Output :
0
Explanation:
There is no lucky permutation in the
given graph.
Your Task:
You don't need to read input or print anything. Your task is to complete the function luckyPermutations() which takes the two integers N and M, an array arr[ ] and a list of lists named graph of size M as input parameters and returns the count of lucky permutations.
Expected Time Complexity: O(N2*2N)
Expected Auxiliary Space: O(N*2N)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/e9e2da3de3eb35679ca7e17b752ae877635f1a26/1
Powered by hirist.com
practice.geeksforgeeks.org
Count Lucky Permutations | Practice | GeeksforGeeks
You are given an array arr[ ] of integers having N elements and a non-weighted undirected graph having N nodes and M edges. The details of each edge in the graph is given to you in the form of list of list.
Your task i
Your task i
Must Do DSA Topics Day 89
Backtracking
Generate a combination of minimum coins that sums to a given value : Given an array arr[] of size N representing the available denominations and an integer X. The task is to find any combination of the minimum number of coins of the available denominations such that the sum of the coins is X.
Learn more : http://bit.ly/3IHlLS7
Generate all possible permutations of a Number divisible by N : Given a numerical string S, the task is to print all the permutations of the string which are divisible by N.
Learn more : http://bit.ly/3Xtkx1a
Print all possible ways to write N as sum of two or more positive integers : Given an integer N, the task is to print all the possible ways in which N can be written as the sum of two or more positive integers.
Learn more : http://bit.ly/3wjcKrj
Get access to all the topics of Backtracking : https://www.geeksforgeeks.org/category/dsa/algorithm/backtracking/
Backtracking
Generate a combination of minimum coins that sums to a given value : Given an array arr[] of size N representing the available denominations and an integer X. The task is to find any combination of the minimum number of coins of the available denominations such that the sum of the coins is X.
Learn more : http://bit.ly/3IHlLS7
Generate all possible permutations of a Number divisible by N : Given a numerical string S, the task is to print all the permutations of the string which are divisible by N.
Learn more : http://bit.ly/3Xtkx1a
Print all possible ways to write N as sum of two or more positive integers : Given an integer N, the task is to print all the possible ways in which N can be written as the sum of two or more positive integers.
Learn more : http://bit.ly/3wjcKrj
Get access to all the topics of Backtracking : https://www.geeksforgeeks.org/category/dsa/algorithm/backtracking/
π1
Problem Of The Day
"Maximum Number of Toys"
Solve the problem to win points
You are given N toys in a shop .
The cost of each toy is represented by an array A[]. You are given Q queries, For ith query, You have a C amount of money which you can use to purchase the toys. Also there are K broken toys and you won't purchase them. The task is to calculate the maximum number of toys you can purchase using the C amount of money.
Note: 1 based indexing is used. Each query is treated independently.
Query definition: The first element represents an integer C where C=Queries[i][0].
The second element represents an integer K, where K = Queries[i][1].
The next K integers represent the indices of broken toys which are Queries[i][j] ,j>1
Example 1:
Input:
N = 5
A[] = {8, 6, 9, 2, 5}
Q = 2
Query[][] = {{12,2,3,4},{30,0}}
Output:
2 5
Explanation:
Query 1: C = 12, K = 2 ,
Indices of Broken toys is {3,4}
Indices of Available toys are {1,2,5}
If we purchase the toys 2 and 5 ,
then cost = A[2]+A[5]= 6+5 = 11,
Therefore,We purchase the 2 toys
using 11 amount of money.
Query 2: C = 30, K = 0
There is no broken toy.
We can purchase all toys,
cost = A[1]+A[2]+A[3]+A[4]+A[5]= 30
Therefore,We purchase the 5 toys
using 30 amount of money.
Example 2:
Input:
N = 2
A[] = {3,3}
Q = 1
Query[][] = {{1,0}}
Output:
0
Explanation:
Query 1: C = 1, K = 0 ,
There is no broken toy.
We have not enough amount to purchase
any toy.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maximumToys() which takes the integer N and array A[ ], integer Q and 2D array Queries[][] as input parameters and returns the array of answers of each query.
Expected Time Complexity: O(NLogMx + Q*K*LogMx + Q*(LogMx)2)
Expected Auxiliary Space: O(Mx)
Where Mx is the maximum element present in the array A[i].
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/maximum-number-of-toys/1
Powered by hirist.com
"Maximum Number of Toys"
Solve the problem to win points
You are given N toys in a shop .
The cost of each toy is represented by an array A[]. You are given Q queries, For ith query, You have a C amount of money which you can use to purchase the toys. Also there are K broken toys and you won't purchase them. The task is to calculate the maximum number of toys you can purchase using the C amount of money.
Note: 1 based indexing is used. Each query is treated independently.
Query definition: The first element represents an integer C where C=Queries[i][0].
The second element represents an integer K, where K = Queries[i][1].
The next K integers represent the indices of broken toys which are Queries[i][j] ,j>1
Example 1:
Input:
N = 5
A[] = {8, 6, 9, 2, 5}
Q = 2
Query[][] = {{12,2,3,4},{30,0}}
Output:
2 5
Explanation:
Query 1: C = 12, K = 2 ,
Indices of Broken toys is {3,4}
Indices of Available toys are {1,2,5}
If we purchase the toys 2 and 5 ,
then cost = A[2]+A[5]= 6+5 = 11,
Therefore,We purchase the 2 toys
using 11 amount of money.
Query 2: C = 30, K = 0
There is no broken toy.
We can purchase all toys,
cost = A[1]+A[2]+A[3]+A[4]+A[5]= 30
Therefore,We purchase the 5 toys
using 30 amount of money.
Example 2:
Input:
N = 2
A[] = {3,3}
Q = 1
Query[][] = {{1,0}}
Output:
0
Explanation:
Query 1: C = 1, K = 0 ,
There is no broken toy.
We have not enough amount to purchase
any toy.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maximumToys() which takes the integer N and array A[ ], integer Q and 2D array Queries[][] as input parameters and returns the array of answers of each query.
Expected Time Complexity: O(NLogMx + Q*K*LogMx + Q*(LogMx)2)
Expected Auxiliary Space: O(Mx)
Where Mx is the maximum element present in the array A[i].
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/maximum-number-of-toys/1
Powered by hirist.com
practice.geeksforgeeks.org
Maximum Number of Toys | Practice | GeeksforGeeks
You are given N toys in a shop .
The cost of each toy is represented by an array A[]. You are given Q queries, For ith query, You have a C amount of money which you can use to purchase the toys. Also there are K broken toys and you wo
The cost of each toy is represented by an array A[]. You are given Q queries, For ith query, You have a C amount of money which you can use to purchase the toys. Also there are K broken toys and you wo
π5
MangoApps is hiring for DevOps Engineer in Pune.
Interested candidates can apply via the following link and also share the opportunity with friends- https://practice.geeksforgeeks.org/jobs/MangoApps-Devops
Interested candidates can apply via the following link and also share the opportunity with friends- https://practice.geeksforgeeks.org/jobs/MangoApps-Devops
π1
Problem Of The Day
"Count the Substring"
Solve the problem to win points
Given a binary string S consists only of 0s and 1s. The task is to calculate the number of substrings that have more 1s than 0s.
Example 1:
Input:
S = "011"
Output: 4
Explanation: There are 4 substring which
has more 1s than 0s. i.e "011","1","11" and "1"
Example 2:
Input:
S = "0000"
Output: 0
Explanation: There is no substring
which has more 1s than 0s
Your Task:
You dont need to read input or print anything. Complete the function countSubstring() which takes the string S as input parameter and returns the number of substring which has more 1s than 0s.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/f72994353d123b925ff20f0694b662191df03ea2/1
Powered by hirist.com
"Count the Substring"
Solve the problem to win points
Given a binary string S consists only of 0s and 1s. The task is to calculate the number of substrings that have more 1s than 0s.
Example 1:
Input:
S = "011"
Output: 4
Explanation: There are 4 substring which
has more 1s than 0s. i.e "011","1","11" and "1"
Example 2:
Input:
S = "0000"
Output: 0
Explanation: There is no substring
which has more 1s than 0s
Your Task:
You dont need to read input or print anything. Complete the function countSubstring() which takes the string S as input parameter and returns the number of substring which has more 1s than 0s.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)
Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/f72994353d123b925ff20f0694b662191df03ea2/1
Powered by hirist.com
practice.geeksforgeeks.org
Count the Substring | Practice | GeeksforGeeks
Given a binary string S consists only of 0s and 1s. The task is to calculate the number of substrings that have more 1s than 0s.
Example 1:
Input:
S = "011"
Output: 4
Explanation: There are 4 substring which
has more
Example 1:
Input:
S = "011"
Output: 4
Explanation: There are 4 substring which
has more
π1