Skip to content

Instantly share code, notes, and snippets.

@rozer007
rozer007 / code.cpp
Last active October 21, 2021 10:35
pepcoding.com 19/10/21 targetSumPair1
#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)
@rozer007
rozer007 / code.cpp
Last active October 21, 2021 10:35
pepcoding.com 19/10/21 sort012
#include <iostream>
#include <vector>
using namespace std;
void input(vector<int> &arr)
{
for (int i = 0; i < arr.size(); i++)
{
cin >> arr[i];
@rozer007
rozer007 / code.cpp
Last active October 21, 2021 10:36
pepcoding.com 19/10/2021 pivotInSortedAndRotatedArray
#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)
@rozer007
rozer007 / Height of a Generic Tree
Last active October 22, 2021 06:35
Height of a Generic Tree
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
@rozer007
rozer007 / Generic Tree - Traversals (pre-order, Post-order)
Last active October 22, 2021 06:37
Generic Tree - Traversals (pre-order, Post-order)
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
@rozer007
rozer007 / Level-order Of Generic Tree
Last active October 22, 2021 06:38
Level-order Of Generic Tree
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
@rozer007
rozer007 / Levelorder Linewise (generic Tree)
Last active October 22, 2021 06:39
Levelorder Linewise (generic Tree)
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:
@rozer007
rozer007 / Level order Linewise Zig Zag
Last active October 22, 2021 06:40
Level order Linewise Zig Zag
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:
@rozer007
rozer007 / Faq
Last active October 26, 2021 09:50
Count Digits In A Number
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.
@rozer007
rozer007 / Faq
Last active October 26, 2021 10:47
Coin Change Combination
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?