GeeksforGeeks
17.4K subscribers
1.83K photos
34 videos
24 files
2.76K links
Official Hub βœ…

Your coding haven – where tech meets simplicity.

Discover:
πŸ˜‚ Coding Laughter
πŸ“˜ Curated Study Material
πŸ’Ž Exclusive Offers

Utilize every service we provide and make a promise to find better opportunities for yourself! #gfgkarlohojayega!
Download Telegram
Wishing you all a very Happy New Year! ❀️
❀25
Problem Of The Day
"Count even length"

Solve the problem to win points

Given a number n, find count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits.
The anwer can be very large. So, you have to return answer modulo 109+7.

Example:
Input: n = 2
Output: 6
Explanation: There are 6 sequences of length
2*n, the sequences are 0101, 0110, 1010, 1001,
0000 and 1111.
Example:

Input: n = 1
Output: 2
Explanation: There are 2 sequence of length
2*n, the sequence are 00 and 11.


Your Task:
You don't need to read or print anyhting. Your task is to complete the function compute_value() which takes n as input parameter and returns count of all binary sequence of length 2*n such that sum of first n bits is same as sum of last n bits modulo 109 + 7.


Expected Time Complexity: O(n * log(n))
Expected Space Complexity: O(1)

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/count-even-length1907/1

Powered by hirist.com
Must Do DSA Topics Day 79
Greedy
Huffman Coding : Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters, lengths of the assigned codes are based on the frequencies of corresponding characters.
Learn more : https://bit.ly/3Ze4UMO

Efficient Huffman Coding for sorted input : We recommend to read following post as a prerequisite for this.
Greedy Algorithms | Set 3 (Huffman Coding)

Time complexity of the algorithm discussed in above post is O(nLogn).
Learn more : https://bit.ly/3WNWgCC

Huffman Decoding : We have discussed Huffman Encoding in a previous post. In this post, decoding is discussed.
Learn more : https://bit.ly/3G7Em75
Problem Of The Day
"Maximum Value"

Solve the problem to win points

Given a binary tree, find the largest value in each level.

Example 1:
Input:
1
/ \
2 3
Output:
1 3
Explanation:
At 0 level, values of nodes are {1}
Maximum value is 1
At 1 level, values of nodes are {2,3}
Maximum value is 3

Example 2:
Input:
4
/ \
9 2
/ \ \
3 5 7
Output:
4 9 7
Explanation:
At 0 level, values of nodes are {4}
Maximum value is 4
At 1 level, values of nodes are {9,2}
Maximum value is 9
At 2 level, values of nodes are {3,5,7}
Maximum value is 7

Your Task:

You don't need to read input or print anything.Your task is to complete the function maximumValue() that takes root node as input parameter and returns a list of integers containing the maximum value at each level. The size of the resultant list should be equal to the height of the binary tree and result[i] should store the maximum value at level i.


Expected Time Complexity: O(N), where N is the number of nodes.
Expected Auxiliary Space: O(H), where H is the height of binary tree.

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/ec277982aea7239b550b28421e00acbb1ea03d2c/1

Powered by hirist.com
πŸ‘1
Must Do DSA Topics Day 80
Greedy
Dial’s Algorithm : Dijkstra’s shortest path algorithm runs in O(Elog V) time when implemented with adjacency list representation (See C implementation and STL based C++ implementations for details).
Learn more : https://bit.ly/3Cgh1ir

Dijkstra’s Algorithm for Adjacency List Representation : We have discussed Dijkstra’s algorithm and its implementation for adjacency matrix representation of graphs. The time complexity for the matrix representation is O(V^2). In this post, O(ELogV) algorithm for adjacency list representation is discussed.
Learn more : https://bit.ly/3Qc0jGS

Prim’s MST for adjacency list representation : The idea is to traverse all vertices of graph using BFS and use a Min Heap to store the vertices not yet included in MST. Min Heap is used as a priority queue to get the minimum weight edge from the cut.
Learn more : https://bit.ly/3G6Nb0R
Hey Freshers! You no longer have to scroll through endless posts to find an opportunity. We got your back.πŸ˜ƒ

Unveiling your New Year Gift with the details of the companies that are hiring freshers in the 'Mega Job-A-Thon 2023' hiring challenge | 4th Jan.βœ¨πŸ™Œ:

Click on the following link to get more details- https://bit.ly/3PMA89y
πŸ‘3
Looking for a better opportunity to switch? Here we are with a range of amazing opportunities.πŸ˜ŒπŸ˜ƒ

Unveiling your New Year Gift with the details of the companies that are hiring experienced candidates in the 'Mega Job-A-Thon 2023' hiring challenge | 5th Jan.β­πŸ™Œ:

Click on the following link for more details- https://bit.ly/3Vv22Ip
Problem Of The Day
"Minimize number of Students to be removed"

Solve the problem to win points

N Students of different heights are attending an assembly. The heights of the students are represented by an array H[]. The problem is that if a student has less or equal height than the student standing in front of him, then he/she cannot see the assembly. Find the minimum number of students to be removed such that maximum possible number of students can see the assembly.


Example 1:
Input:
N = 6
H[] = {9, 1, 2, 3, 1, 5}
Output:
2
Explanation:
We can remove the students at 0 and 4th index.
which will leave the students with heights
1,2,3, and 5.
Example 2:
Input:
N = 3
H[] = {1, 2, 3}
Output :
0
Explanation:
All of the students are able to see the
assembly without removing anyone.

Your Task:
You don't need to read input or print anything. Your task is to complete the function removeStudents() which takes an integer N and an array H[ ] of size N as input parameters and returns the minimum number of students required to be removed to enable maximum number of students to see the assembly.


Expected Time Complexity: O(N logN)
Expected Auxiliary Space: O(N)

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/7d0fa4007b8eabadc404fcc9fa917aa52982aa96/1

Powered by hirist.com
πŸ‘2
Must Do DSA Topics Day 81
Greedy
Minimum product subset of an array : Given array a, we have to find the minimum product possible with the subset of elements present in the array. The minimum product can be a single element also.
Learn more : https://bit.ly/3X4U1Lr

Maximum product subset of an array : Given an array a, we have to find the maximum product possible with the subset of elements present in the array. The maximum product can be a single element also.
Learn more : https://bit.ly/3VA1Ebq

Maximize the sum of arr[i]*i : Given an Array of N integers, the task is to maximize the value of the product of each array element with their corresponding indices by rearranging the array.
Learn more : https://bit.ly/3WX2yQk
Your dream job is just a click away. Book your calendar | 4th and 5th January.πŸ™Œ

Don't miss your chance!✨

Register for the hiring challenge Mega Job-A-Thon 2023. Get more details and register using the following link- http://bit.ly/3hIK9aS
πŸ‘2
Problem Of The Day
"Maximum Profit By Choosing A Subset Of Intervals"

Solve the problem to win points

Given a list intervals of n intervals, the ith element [s, e, p] denotes the starting point s, ending point e, and the profit p earned by choosing the ith interval. Find the maximum profit one can achieve by choosing a subset of non-overlapping intervals.

Two intervals [s1, e1, p1] and [s2, e2, p2] are said to be non-overlapping if [e1 <= s2] and [s1 < s2].

Example 1:
Input:
n = 3
intervals = {
{1, 2, 4},
{1, 5, 7},
{2, 4, 4}
}
Output:
8
Explanation:
One can choose intervals [1, 2, 4] and [2, 4, 4] for a
profit of 8.

Example 2:
Input:
n = 3
intervals = {
{1, 4, 4},
{2, 3, 7},
{2, 3, 4}
}
Output:
7
Explanation:
One can choose interval [2, 3, 7] for a profit of 7.

Your Task:
You don't need to print or output anything. Complete the function maximum_profit() which takes an integer n and a 2D integer array intervals and returns an integer, denoting the maximum profit which one can get by choosing the non-overlapping intervals.

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/649205908e04ac00f303626fa845261318adfa8f/1

Powered by hirist.com
Must Do DSA Topics Day 82
Greedy
First Fit algorithm in Memory Management : In the first fit, the partition is allocated which is first sufficient from the top of Main Memory.
Learn more : https://bit.ly/3WUlLSO

Best Fit algorithm in Memory Management : Best fit allocates the process to a partition which is the smallest sufficient partition among the free available partitions.
Learn more : https://bit.ly/3Z8eNvi

Worst Fit algorithm in Memory Management : Worst Fit allocates a process to the partition which is largest sufficient among the freely available partitions available in the main memory.
Learn more : https://bit.ly/3GzFFNv
Get! Set! Go!!!πŸ™Œ
Finally the most awaited Mega Job-A-Thon 2023 has begun for freshers/interns. Plus, just a day to go for experienced candidates.πŸ˜ƒ

Stop waiting and grab the best opportunities now.🀌

Hurry up!

Click on the following link to register - http://bit.ly/3hIK9aS
πŸ‘1
Problem Of The Day
"Find the longest string"

Solve the problem to win points

Given an array of strings arr[]. You have to find the longest string which is lexicographically smallest and also all of its prefix strings are already present in the array.

Example 1:
Input: ab a abc abd
Output: abc
Explanation: We can see that length of the longest
string is 3. And there are two string "abc" and "abd"
of length 3. But for string "abc" , all of its prefix
"a" "ab" "abc" are present in the array. So the
output is "abc".

Example 2:
Input: ab a aa abd abc abda abdd abde abdab
Output: abdab
Explanation: We can see that each string is fulfilling
the condition. For each string, all of its prefix
are present in the array.And "abdab" is the longest
string among them. So the ouput is "abdab".


Your Task:
You don't need to read input or print anything. Your task is to complete the function longestString() which takes the array arr[] as input parameter and returns the longest string which is also lexicographically smallest.And if there is no such string return empty string.


Expected Time Complexity: O(NlogN)
Expected Space Complexity: O(N)

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/8d157f11af5416087251513cfc38ffc4d23be308/1

Powered by hirist.com
πŸ‘1
Must Do DSA Topics Day 83
Greedy
Set cover problem : Given a universe U of n elements, a collection of subsets of U say S = {S1, S2…,Sm} where every subset Si has an associated cost. Find a minimum cost subcollection of S that covers all elements of U.
Learn more : https://bit.ly/3GfkY8h

Bin Packing Problem : Given n items of different weights and bins each of capacity c, assign each item to a bin such that number of total used bins is minimized. It may be assumed that all items have weights smaller than bin capacity.
Learn more : https://bit.ly/3VQBi50

Graph Coloring : As discussed in the previous post, graph coloring is widely used. Unfortunately, there is no efficient algorithm available for coloring a graph with minimum number of colors as the problem is a known NP Complete problem.
Learn more : https://bit.ly/3WMa0y7
Job AlertπŸ’Ό

kbx Digital is hiring for a Software Development Engineer role in Chennai. Candidates must have experience of over 1 to 7 years.

Click on the following link for more details and to apply, also, share the opportunity with your friends- https://practice.geeksforgeeks.org/jobs/KBXDigitalSDE
Problem Of The Day
"Shortest Prime Path"

Solve the problem to win points

You are given two four digit prime numbers Num1 and Num2. Find the distance of the shortest path from Num1 to Num2 that can be attained by altering only one single digit at a time. Every number obtained after changing a digit should be a four digit prime number with no leading zeros.


Example 1:
Input:
Num1 = 1033
Num2 = 8179
Output: 6
Explanation:
1033 -> 1733 -> 3733 -> 3739 -> 3779
-> 8779 -> 8179.
There are only 6 steps required to reach
Num2 from Num1, and all the intermediate
numbers are 4 digit prime numbers.

Example 2:
Input:
Num1 = 1033
Num2 = 1033
Output:
0

Your Task:
You don't need to read input or print anything. Your task is to

Complete the constructor of the class Solution to precompute a list of prime numbers.
Complete function shortestPath() which takes two integers Num1 and Num2 as input parameters and returns the distance of the shortest path from Num1 to Num2. If it is unreachable then return -1.

Expected Time Complexity: O(NlogN)
Expected Auxiliary Space: O(N)

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/1646a9b5169d7571cf672f2a31533af083d1f479/1

Powered by hirist.com
πŸ‘2
Must Do DSA Topics Day 84
Greedy
Split n into maximum composite numbers : Given n, print the maximum number of composite numbers that sum up to n. First few composite numbers are 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, ………
Learn more : https://bit.ly/3vI1zYE

Maximum trains for which stoppage can be provided : We are given n-platform and two main running railway track for both direction. Trains which needs to stop at your station must occupy one platform for their stoppage and the trains which need not to stop at your station will run away through either of main track without stopping.
Learn more : https://bit.ly/3ZgvnsP

Buy Maximum Stocks if i stocks can be bought on i-th day : In a stock market, there is a product with its infinite stocks. The stock prices are given for N days, where arr[i] denotes the price of the stock on the ith day.
Learn more : https://bit.ly/3GM482p

Get access to all the topics of Greedy : https://www.geeksforgeeks.org/greedy-algorithms/?ref=gcse
πŸ‘2
Hey Geeks! We won't let you give up on your resolutions this year.πŸ˜ƒπŸ€Œ

Resolution Days sale of 2023 is live now!!!✨

Click on the following link to avail exciting offers - https://practice.geeksforgeeks.org/courses?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=rd2023
πŸ‘1πŸ”₯1
Problem Of The Day
"Flattening a Linked List"

Solve the problem to win points

Given a Linked List of size N, where every node represents a sub-linked-list and contains two pointers:
(i) a next pointer to the next node,
(ii) a bottom pointer to a linked list where this node is head.
Each of the sub-linked-list is in sorted order.

Flatten the Link List such that all the nodes appear in a single level while maintaining the sorted order.

Note: The flattened list will be printed using the bottom pointer instead of next pointer.

Example 1:
Input:
5 -> 10 -> 19 -> 28
| | | |
7 20 22 35
| | |
8 50 40
| |
30 45
Output: 5-> 7-> 8- > 10 -> 19-> 20->
22-> 28-> 30-> 35-> 40-> 45-> 50.
Explanation:
The resultant linked lists has every
node in a single level.
(Note: | represents the bottom pointer.)

Example 2:
Input:
5 -> 10 -> 19 -> 28
| |
7 22
| |
8 50
|
30
Output: 5->7->8->10->19->22->28->30->50
Explanation:
The resultant linked lists has every
node in a single level.

(Note: | represents the bottom pointer.)

Your Task:
You do not need to read input or print anything. Complete the function flatten() that takes the head of the linked list as input parameter and returns the head of flattened link list.

Expected Time Complexity: O(N*M)
Expected Auxiliary Space: O(1)

Solve and submit your answer here : https://practice.geeksforgeeks.org/problems/da62a798bca208c7a678c133569c3dc7f5b73500/1

Powered by hirist.com
πŸ‘5