This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
void input(vector<int> &arr) | |
{ | |
for (int i = 0; i < arr.size(); i++) | |
{ | |
cin >> arr[i]; | |
} | |
} | |
int findpivot(vector<int>&arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void input(vector<int> &arr) | |
{ | |
for (int i = 0; i < arr.size(); i++) | |
{ | |
cin >> arr[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
void input(vector<int> &arr) | |
{ | |
for (int i = 0; i < arr.size(); i++) | |
{ | |
cin >> arr[i]; | |
} | |
} | |
void targetSumPair(vector<int> &arr,int target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
In this problem you are given a partially written GenericTree class. | |
All you need to do is to complete the body of height function. | |
The function is expected to find the height of the tree. Depth of a node is defined as the number of edges it is away from the root (depth of root is 0). Height of a tree is defined as the depth of the deepest node. | |
Question Name: | |
Height of a Generic Tree | |
Question Link: | |
https://www.pepcoding.com/resources/online-java-foundation/generic-tree/height-of-generic-tree-official/ojquestion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
"Traversals in Generic Tree" where we are going to discuss Pre-order and Post-order traversals. | |
This is a great question to get in depth knowledge on how traversals work which will be beneficial for understanding other questions as well. | |
Question Name: | |
Generic Tree - Traversals (pre-order, Post-order) | |
Question Link: | |
https://www.pepcoding.com/resources/online-java-foundation/generic-tree/generic-tree-traversal-official/ojquestion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
In this problem you are given a partially written GenericTree class. | |
All you need to do is to complete the body of the levelorder function. The function is expected to visit every node in "levelorder fashion" while printing the tree top to bottom levels from left to right where the nodes are separated by spaces. | |
Question Name: | |
Level-order Of Generic Tree | |
Question Link: | |
https://www.pepcoding.com/resources/online-java-foundation/generic-tree/level-order-generic-tree-official/ojquestion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
We have to print the level order of a generic tree line wise i.e. all the elements which belong to the same level should be printed in one line and the elements of the next levels should be printed in the next line. | |
Question Name: | |
Levelorder Linewise Of Generic Tree | |
Question Link: | |
https://www.pepcoding.com/resources/online-java-foundation/generic-tree/levelorder-linewise-generic-tree-official/ojquestion | |
Question Statement: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description: | |
You are required to complete the body of levelorderLineWiseZZ function. The function is expected to visit every node in "levelorder fashion" but in a zig-zag manner. | |
Question Name: | |
Level order Linewise Zig Zag Of Generic Tree | |
Question Link: | |
https://www.pepcoding.com/resources/online-java-foundation/generic-tree/levelorder-linewise-zigzag-official/ojquestion | |
Question Statement: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) Why is the while loop condition (n>0) not (n>=0)? | |
ans: If n==0 then there is no more digit present so, if you keep (n>=0) then it will give one more count extra. | |
Therefore, we are using n>0. | |
Q2) Why while loop not for loop? | |
ans: We can use any of the loop,even if you use for loop it will give you same solution. | |
Q3) why are we doing n=n/10? | |
ans: When we divide a number by 10, the digit in that number is decrease by one so, by dividing the count of digit present in that number. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) why do we create dp array of size n+1 not n? | |
ans: Since the array indexing start from 0 if we create a array od n size then index will be for 0 to n-1.Therefore we are creating array with size n+1. | |
Q2) What is the meaning of cells for the dp array? | |
ans: cells represents the max combination possible of that amount i.e the index. | |
Q3) In which direction the array will be traverse? | |
ans: From left to right. | |
Q4) Where will be the answer present? |
OlderNewer