Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
pradhuman7d1 / faq
Last active October 26, 2021 11:13
Pattern 5
1) Why we use line change outside the inner loops ?
Answer) We change the line for once only after executing both inner loops
because our inner loops work for the columns, and the outer loop works for the row.
_________________________________________________________________
2) Why pattern is not printing properly in case of even input ?
Answer) We do not get the desired pattern for even values of 'n' because, for this pattern we increment our stars upto the mid row,
but in case of even input, we do not get a proper line for seperation. So, the pattern prints correctly initially, but after the first half
the pattern won't look as desired.
@pradhuman7d1
pradhuman7d1 / faq
Created October 26, 2021 08:24
Print Permutations
1) Suppose if we are given only the length of string, can you print the number of permutations ?
Answer) yes, number permutions are simply equal to the factorial of length of string, like,
if we have length of string as 4 then total number of permutations is going to be
4 * 3 * 2 * 1 = 24
(think and maditate for more approaches)
_________________________________________________________________
2) Can there be a non recursive approach ?
@pradhuman7d1
pradhuman7d1 / Saddle Price
Created October 22, 2021 06:47
Saddle Price
Description:
Another question that will help you get better understanding of arrays data structure, in this you have to find an element that is smallest in the respective row and largest in the column. Watch video for better understanding.
Question Name:
Saddle Price
Question Link :
https://www.pepcoding.com/resources/online-java-foundation/2d-arrays/saddle-price-official/ojquestion
Question Statement:
@pradhuman7d1
pradhuman7d1 / The State Of Wakanda - 2
Created October 22, 2021 06:40
The State Of Wakanda - 2
Description:
he historic state of Wakanda has various monuments and souveniers which are visited by many travellers every day. The guides follow a prescribed route of visiting the monuments which improves them understand the relevance of each monument. The route of the monument is fixed and expressed in a 2-d matrix where the travellers visit the prescribed next monument. For example
1 2 3
4 5 6
7 8 9
is the prescribed route and the visitors travels this path: 1->2->3->4->5->6->7->8->9
However, a certain visitor decides to travel a different path as follows:
1. The visitor only plans to visit the upper diagonal triangle of the monument list.
2. The visitor travels diagonally till there are no more moves left in the current journey.
3. He then visits the adjacent monument to the first monument of current diagonal journey.
@pradhuman7d1
pradhuman7d1 / Ring Rotate
Created October 22, 2021 06:29
Ring Rotate
Description:
This one is a rather important question, brief intro is provided in question statement, take that as reference, but, we suggest you to watch the video for better understanding of the problem
Question Name:
Ring Rotate
Question Link:
https://www.pepcoding.com/resources/online-java-foundation/2d-arrays/ring-rotate-official/ojquestion
Question Statement:
@pradhuman7d1
pradhuman7d1 / Rotate By 90 Degree
Created October 22, 2021 06:28
Rotate By 90 Degree
Description:
In this problem we are required to rotate a matrix by 90 degrees, so for that we need to first transpose the matrix and then mirror it's row elements, basically swap its row elements like first with last and so on, watch the video for better understanding.
Question Name:
Rotate By 90 Degree
Question Link :
https://www.pepcoding.com/resources/online-java-foundation/2d-arrays/rotate-by-90-degree-official/ojquestion
Question Statement:
@pradhuman7d1
pradhuman7d1 / Exit Point of a Matrix
Created October 22, 2021 06:27
Exit Point of a Matrix
Description:
This problem is to improve your knowledge about basics of java and also to make you familiar with the data structure - Arrays.
In this problem we will start from the top left corner and traverse through the array with the constraint that whenever we encounter a cell containing a 1, we will take a 90° right turn, and will move straight while we encounter a 0.
Thats it about the problem, watch the video and have fun while learning...
Question Name:
Exit Point of a Matrix
Question Link:
https://www.pepcoding.com/resources/online-java-foundation/2d-arrays/exit-point-matrix-official/ojquestion
@pradhuman7d1
pradhuman7d1 / code.cpp
Created October 21, 2021 10:12
pepcoding.com 21/10/2021 printEncodings
#include <iostream>
#include<string>
using namespace std;
void printEncoding(string str, string asf){
if(str.length() == 0) { // base case
cout << asf << endl;
return;
}
@pradhuman7d1
pradhuman7d1 / code.cpp
Last active October 21, 2021 10:18
pepcoding.com 21/10/2021 printPermutations
#include <iostream>
using namespace std;
void printPermutations(string str, string asf){
if(str.length() == 0) { // base case
cout << asf << endl;
return;
}
for(int i = 0; i < str.length(); i++) { // loop for traversing the string
@pradhuman7d1
pradhuman7d1 / code.cpp
Created October 21, 2021 10:07
pepcoding.com 21/10/2021 printMazePathsWithJumps
#include<iostream>
using namespace std;
void printMazePathsWithJumps(int sr, int sc, int dr, int dc, string psf) {
if(sr == dr && sc == dc) { //base case
cout << psf << endl;
return;
}