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
Problem Of The Day
"Optimal Array"

Solve the problem to win points

You are given a sorted array a of length n. For each i(0<=i<=n-1), you have to make all the elements of the array from index 0 till i equal, using minimum number of operations. In one operation you either increase or decrease the array element by 1.

You have to return a list which contains the minimum number of operations for each i, to accomplish the above task.

Note:
1. 0-based indexing.
2. For each index, you need to consider the same array which was given to you at the start.

Example 1:
Input:
N=4
A={1,6,9,12}

Output:
0 5 8 14

Explanation:
For i=0, We do not need to perform any
operation, our array will be {1}->{1}.
And minimum number of operations
will be 0.

For i=1, We can choose to convert all
the elements from 0<=j<=i to 4, our
array will become {1,6}->{4,4}. And
minimum number of operations will be
|1-4|+|6-4|=5.

For i=2, We can choose to convert all
the elements from 0<=j<=i to 6, our
array will become {1,6,9}->{6,6,6} and
the minimum number of operations will
be |1-6|+|6-6|+|9-6|=8.

Similarly, for i=3, we can choose to
convert all the elements to 8,
{1,6,9,12}->{8,8,8,8}, and the
minimum number of operations will be 14.

Example 2:
Input:
N=7
A={1,1,1,7,7,10,19}

Output:
0 0 0 6 12 21 33

Explanation:
Possible operations could be:
{1}->{1}
{1,1}->{1,1}
{1,1,1}->{1,1,1}
{1,1,1,7}->{1,1,1,1}
{1,1,1,7,7}->{1,1,1,1,1}
{1,1,1,7,7,10}->{5,5,5,5,5,5}
{1,1,1,7,7,10,19}->{7,7,7,7,7,7,7}

Your Task:
You don't need to read input or print anything. Your task is to complete the function optimalArray() which takes N(length of array) and an array A as input and returns an array of size N with optimal answer for each index i.

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

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

Powered by hirist.com
Must Learn!πŸ’‘
Building projects is one of the best ways to learn C++. It provides valuable practical experience that enables us to make use of the concepts we learned to make something productive.

While building projects, we get to learn how to use different tools and solve different problems enhancing our ability to write code and problem-solving skills. It is also a great way to showcase one’s skills to a potential employer or client.

This article contains the 50 most popular and useful C++ project ideas for beginners, intermediate, and experts. Give it a read.

Link- https://www.geeksforgeeks.org/top-50-cpp-project-ideas-for-beginners-advanced/?utm_sour[…]_medium=marketingteam_gfgmain&utm_campaign=cppprojectideas
πŸ‘2πŸ”₯1
Problem Of The Day
"Update Queries"

Solve the problem to win points

You are given an array of n elements, initially all a[i] = 0. Q queries need to be performed. Each query contains three integers l, r, and x and you need to change all a[i] to (a[i] | x) for all l ≀ i ≀ r.

Return the array after executing Q queries.

Example 1:
Input:
N=3, Q=2
U=[[1, 3, 1],
[1, 3, 2]]

Output:
a[]={3,3,3}

Explanation:
Initially, all elements of the array are 0. After execution of the
first query, all elements become 1 and after execution of the
second query all elements become 3.

Example 2:
Input:
N=3, Q=2
U=[[1, 2, 1],
[3, 3, 2]]

Output:
a[]={1,1,2}

Explanantion:
[0,0,0] => [1,1,0] => [1,1,2]


Your Task:
You don't need to read input or print anything. Your task is to complete the function updateQuery() which takes the integer N,Q, and U a QX3 matrix containing the Q queries where U[i][0] is li, U[i][1] is ri andU[i][2] is xi.and it returns the final array a.

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

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

Powered by hirist.com
πŸ‘4
Must Learn!πŸ’‘
A full stack developer is a person who is an expert in designing, building, maintaining, and updating both the front end and back end of a website or a web application.

So, what are the requirements one has to fulfill in order to become a full stack developer?

This article talks about the role of full stack developers in detail. Give it a read.

Link- https://www.geeksforgeeks.org/requirements-to-become-a-full-stack-developer/?utm_source[…]dium=marketingteam_gfgmain&utm_campaign=fullstackdeveloper
πŸ‘1😁1
Problem Of The Day
"Walls Coloring II"

Solve the problem to win points

There is a row of N walls in Geeksland. The king of Geeksland ordered Alexa to color all the walls on the occasion of New Year. Alexa can color each wall with one of the K colors. The cost associated with coloring each wall with a particular color is represented by a 2D costs array of size N * K. For example, costs[0][0] is the cost of coloring wall 0 with color 0; costs[1][2] is the cost of coloring wall 1 with color 2, and so on... Find the minimum cost to color all the walls such that no two adjacent walls have the same color.

Note: If you are not able to paint all the walls, then you should return -1.

Example 1:
Input:
N = 4, K = 3
costs[][] = {{1, 5, 7},
{5, 8, 4},
{3, 2, 9},
{1, 2, 4}}

Output:
8
Explanation:
Paint wall 0 with color 0. Cost = 1
Paint wall 1 with color 2. Cost = 4
Paint wall 2 with color 1. Cost = 2
Paint wall 3 with color 0. Cost = 1
Total Cost = 1 + 4 + 2 + 1 = 8

Example 2:
Input:
N = 5, K = 1
costs[][] = {{5},
{4},
{9},
{2},
{1}}
Output:
-1
Explanation:
It is not possible to color all the walls under the given conditions.


Your Task:
Your task is to complete the function minCost() which takes a 2D integer matrix costs as the only argument and returns an integer, representing the minimum cost to paint all the walls. If you are not able to paint all the walls, then you should return -1

Expected Time Complexity: O(N*K)
Expected Space Complexity: O(N*K)

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

Powered by hirist.com
πŸ‘1
This media is not supported in your browser
VIEW IN TELEGRAM
Must Learn!πŸ’‘
JavaScript is by far of the most popular languages when it comes to web development, powering most websites and web applications.

There are ways to use Java in an enhanced manner and every Java Developer should be aware of them.

This article deals with the forementioned topic in detail. Give it a read.

Link- https://www.geeksforgeeks.org/8-tips-and-tricks-for-javascript-developers/?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=javascriptdevelopers
Looking for a switch?

Well, we are here with endless opportunities at 'GeeksforGeeks Jobs Fair 2023'.πŸ˜ƒπŸ€Œ

This is the right move to give a boost to your career.πŸ’«

Start applying now - https://practice.geeksforgeeks.org/jobs?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=jobfair2023
πŸ”₯2
Problem Of The Day
"Cutting Rectangles"

Solve the problem to win points

Given a rectangle of dimensions L x B find the minimum number (N) of identical squares of maximum side that can be cut out from that rectangle so that no residue remains in the rectangle. Also find the dimension K of that square.

Example 1:
Input: L = 2, B = 4
Output: N = 2, K = 2
Explaination: 2 squares of 2x2 dimension.

Example 2:
Input: L = 6, B = 3
Output: N = 2, K = 3
Explaintion: 2 squares of 3x3 dimension.

Your Task:
You do not need to read input or print anything. Your task is to complete the function minimumSquares() which takes L and B as input parameters and returns a list of 2 integers containing the values of N and K respectively.

Expected Time Complexity: O(log min(L, B))
Expected Auxiliary Space: O(1)

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

Powered by hirist.com
Must Learn!πŸ’‘
What is it that never goes out of trend/trolls/twists? The answer is Cryptocurrency. Cryptocurrency is a form of digital money.

In March 2021 when Bitcoin was at its all-time high, almost all the investors thought they’d get filthy rich. Cut to July 2021, Bitcoin prices dropped by 50% and it soared through the year and most of 2022, recording its lowest at $29,000 in May 2022.

So, how will you evaluate the benefits and risks of Cryptocurrency?

This article deals with the mentioned issue. Give it a read.

Link- https://www.geeksforgeeks.org/cryptocurrency-good-or-bad-investment/?utm_source=telegra[…]m_medium=marketingteam_gfgmain&utm_campaign=cryptocurrency
Problem Of The Day
"Best Node"

Solve the problem to win points

You are given a tree rooted at node 1. The tree is given in form of an array P where Pi denotes the parent of node i, Also P1 = -1, as 1 is the root node. Every node i has a value Ai associated with it. At first, you have to choose any node to start with, after that from a node you can go to any of its child nodes. You've to keep moving to a child node until you reach a leaf node. Every time you get to a new node, you write its value. Let us assume that the integer sequence in your path is B.

Let us define a function f over B, which is defined as follows:
f(B) = B1 - B2 + B3 - B4 + B5.... + (-1)(k-1)Bk.
You have to find the maximum possible value of f(B).

Example 1:
Input:
N = 3,
A = { 1, 2, 3}
P = {-1, 1, 1}
Output:
3
Explanation:
The resulting tree is:
1(1)
/ \
2(2) 3(3)
If we choose our starting node as 3, then the
resulting sequence will be B = { 3 },
which will give the maximum possible value.

Example 2:
Input:
N = 3,
A = { 3, 1, 2}
P = {-1, 1, 2}
Output:
4
Explanation:
The resulting tree is:
1(3)
|
2(1)
|
3(2)
If we choose our starting node as 1, then the
resulting sequence will be B = { 3 , 1 , 2 }.
The value which we'll get is, 3-1+2 = 4, which
is the maximum possible value.
Your Task:
The task is to complete the function bestNode() which takes an integer N and two integer arrays A, P as input parameters and returns the maximum possible value possible.

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

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

Powered by hirist.com
πŸ‘1
Must Learn!πŸ’‘
The method of producing animated images and visual effects with computer software is referred to as software animation.

Several industries, including film and television, video games, advertising, and web design, might benefit from software animation.

However, it is confusing for beginners to decide about which software to use for the animation. This article will help you sort it out. Give it a read.

Link- https://www.geeksforgeeks.org/best-animation-softwares-for-beginers/?utm_source=telegra[…]m=marketingteam_gfgmain&utm_campaign=bestanimationsoftware
πŸ‘1
🚨Job Alert🚨
Geninvo is hiring for Full Stack Developer (Java).

Location - Mohali (Chandigarh)
Experience - 2 - 8 Years
Apply by - Mar 15, 2023

Apply via the following link and share the opportunity with your friends- https://practice.geeksforgeeks.org/jobs/Geninvo-Fullstack-developer

πŸ“’: Also, do not miss the chance to get endless opportunities at Jobs Fair 2023 - https://practice.geeksforgeeks.org/jobs?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=jobfair2023
πŸ‘2
Problem Of The Day
"Avoid Explosion"

Solve the problem to win points

Geek is a chemical scientist who is performing an experiment to find an antidote to a poison. The experiment involves mixing some solutions in a flask. Based on the theoretical research Geek has done, he came up with an n * 2 array 'mix', where mix[i] = {X, Y} denotes solutions X and Y that needs to be mixed.

Also, from his past experience, it has been known that mixing some solutions leads to an explosion and thereby completely ruining the experiment. The explosive solutions are also provided as a m * 2 array 'danger' where danger[i] = {P, Q} denotes that if somehow solutions P and Q get into the same flask it will result in an explosion.

Help the Geek by returning an array 'answer' of size n, where answer[i] = "Yes" if it is safe to mix solutions in 'mix[i]' or else answer[i] = "No".

Note: Geek should follow the order of mixing of solutions as it is in 'mix' otherwise the antidote will be ineffective. Also, Geek will not mix the solutions in 'mix[i]' once he gets to know that mixing them will result in an explosion. Mixing a solution will effect the other solutions which will appear after it.

Example 1:
Input:
n = 5, m = 2
mix = {{1, 2}, {2, 3}, {4, 5}, {3, 5}, {2, 4}}
danger = {{1, 3}, {4, 2}}

Output:
answer = {"Yes", "No", "Yes", "Yes", "No"}

Explanation:
Mixing the first solution(1 and 2) of 'mix' do not result in any kind of explosion hence answer[0] is "Yes", while mixing(2nd solution) 2 and 3 is not allowed because it will result in an explosion as 1 and 3 would be in same solution hence we have returned "No" as the answer for 2nd solution. Mixing the third solution(4 and 5) and 4th solution(3 and 5) of 'mix' do not result in any kind of explosion hence answer[2] and answer[3] is "Yes". While mixing 2 and 4 is not allowed because it will result in an explosion hence we have returned "No" as the answer for it.

Example 2:
Input:
n = 3, m = 2
mix = {{1, 2}, {2, 3}, {1, 3}}
danger = {{1, 2}, {1, 3}}

Output:
answer = {"No", "Yes", "No"}

Explanation:
Mixing solutions 1 and 2 is dangerous hence
answer[0] = "No", but solutions 2 and 3 can
be mixed without any problem therefore answer[1]
= "Yes". Again, mixing solutions 1 and 3 is
dangerous due to which answer[2] = "No".


Your Task:
You don't need to read input or print anything. Complete the function avoidExplosion() which takes the mix array, its size, danger array, and its size as input parameters and returns the result array or list.

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

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

Powered by hirist.com
πŸ‘1
Must Learn!πŸ’‘
Adobe Dreamweaver is among the finest platform where you can create webpages, and that too with multiple language support (such as HTML, CSS, JavaScript, etc.).

The tool and functions of this platform allow users to create more responsive designs that can perform well on all devices, such as Mobile, Tablet, Desktop, etc.

This article will introduce you with the 10 best dreamweaver alternativeas in Linux. Give it a read.

Link- https://www.geeksforgeeks.org/10-best-adobe-dreamweaver-alternatives-for-linux/?utm_sou[…]medium=marketingteam_gfgmain&utm_campaign=adobedreamweaver
πŸ‘1πŸ‘Ž1
Problem Of The Day
"Geek hates too many 1s"

Solve the problem to win points

Given an non-negative integer n. You are only allowed to make set bit unset. You have to find the maximum possible value of query so that after performing the given operations, no three consecutive bits of the integer query are set-bits.

Example 1:
Input:
n = 2
Output:
2
Explanation:
2's binary form is 10, no 3 consecutive set bits are here.
So, 2 itself would be answer.

Example 2:
Input:
n = 7
Output:
6
Explanation:
7's binary form is .....00111.We can observe that 3
consecutive bits are set bits. This is not allowed.
So, we can perfrom the operation of changing set
bit to unset bit. Now, the number
becomes 6 that is .....00110. It satifies the
given condition. Hence, the maximum possible
value is 6.

Your Task: You don't need to read input or print anything. Your task is to complete the function noConseBits(), which takes integer n as input parameter and returns the maximum value possible so that it satifies the given condition.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

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

Powered by hirist.com
❀1πŸ‘Ž1
Making your first move for your career is much easier with a range of opportunities at Jobs Fair 2023.✨ Till 20th March...!

Don't wait...Hurry up!

This is the right time and right move to kickstart your career.πŸ˜ƒπŸ€Œ

Get hired - https://practice.geeksforgeeks.org/jobs?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=jobfair2023
πŸ‘1πŸ‘Ž1
Must Learn!πŸ’‘
If you are an aspiring Java Developer, then you must be aware of the fact that it is one of the sought-after domains nowadays.

While it is among popular programming language, it is becoming advanced with each passing year. Being a developer you must update yourself along.

This article talks about the top 12 Java developer skills that you as a programmer, must have in 2023. Give it a read.

Link- https://www.geeksforgeeks.org/top-12-java-developer-skills-that-you-must-have/?utm_source=telegram&utm_medium=marketingteam_gfgmain&utm_campaign=javadevelopers
❀1πŸ‘Ž1
Problem Of The Day
"Max Level Sum in Binary Tree"

Solve the problem to win points

Given a Binary Tree having positive and negative nodes. Find the maximum sum of a level in the given Binary Tree.

Example 1:
Input :
4
/ \
2 -5
/ \ / \
-1 3 -2 6

Output: 6

Explanation :
Sum of all nodes of 0'th level is 4
Sum of all nodes of 1'th level is -3
Sum of all nodes of 2'th level is 6
Hence maximum sum is 6

Example 2:
Input :
1
/ \
2 3
/ \ \
4 5 8
/ \
6 7

Output : 17

Explanation: Maximum sum is at level 2.

Your Task:
You dont need to read input or print anything. Complete the function maxLevelSum() which takes root node as input parameter and returns the maximum sum of any horizontal level in the given Binary Tree.

Expected Time Complexity: O(N), where N is no of node.
Expected Auxiliary Space: O(W), Where W is the max width of the tree.

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

Powered by hirist.com
❀1πŸ‘Ž1
Must Learn!πŸ’‘
AI or Artificial Intelligence is the most-talked topic and the entry of ChatGPT and Google Bard has left people stunned.

These AI tools are capable of doing anything and any work, from giving answers to each question, making taglines to solving papers.

It's complicated to choose between both the tool and indentify the difference between them. However, there are significant differences between ChatGPT and Google Bard.

This article talks about both the tools, their utilities, and difference between them in detail. Give it a read.

Link- https://www.geeksforgeeks.org/chatgpt-vs-google-bard-top-differences-that-you-should-know/?utm_source=Telegram&utm_medium=marketingteam_gfgmain&utm_campaign=chatgpt-googlebard