Skip to content

Instantly share code, notes, and snippets.

@cypher-nullbyte
Last active May 16, 2020 08:35
Show Gist options
  • Save cypher-nullbyte/d3964f9ecd33edf098ca47223ff29936 to your computer and use it in GitHub Desktop.
Save cypher-nullbyte/d3964f9ecd33edf098ca47223ff29936 to your computer and use it in GitHub Desktop.
Vpropel VIT | POD | 08/05/2020 | Point to Point | Similar to Frog Jump 404 LeetCode
#include<stdio.h>
int n,m=0,arr[80];
void check(int i,int j)
{
if(i<n && m!=1)
{
int d,e,f;
d=arr[i]-arr[i-1];
if(d==j || d==j-1 || d==j+1)
{
if(i==n-1)
{
m=1;
printf("Yes");
return ;
}
check(i+1,d);
}
e=arr[i+1]-arr[i-1];
if(e==j || e==j-1 || e== j+1)
{
if(i==n-1)
{
m=1;
printf("Yes");
return ;
}
check(i+2,e);
}
}
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
check(2,1);
if(m==0)
printf("No");
return 0;
}
//Dpk IS-19 CI0003
#include<iostream>
int n,m=0,arr[80];
void check(int i,int j)
{
if(i<n && m!=1)
{
int d,e,f;
d=arr[i]-arr[i-1];
if(d==j || d==j-1 || d==j+1)
{
if(i==n-1)
{
m=1;
std::cout<<"Yes";
exit(0);
}
check(i+1,d);
}
e=arr[i+1]-arr[i-1];
if(e==j || e==j-1 || e== j+1)
{
if(i==n-1)
{
m=1;
std::cout<<"Yes";
exit(0);
}
check(i+2,e);
}
}
}
int main()
{
std::cin>>n;
for(int i=0;i<n;i++)
std::cin>>arr[i];
check(2,1);
if(m==0)
std::cout<<"No";
return 0;
}
//Dpk IS-19 CI0003
Point to Point
Shyam is standing in Point A. He has to reach Point B. There are m number of divisions
between Point A and point B.
These division may or may not have a stone. One can jump only on the stone.
Given a list of stones positions (in division) in sorted ascending order,
determine whether Shyam can reach Point B.
Initially Shyam is at the first stone and assume the first jump is one division
If Shyam’s last jump is k divisions the he can either k-1 or k or k+1 divisions in the next jump.
He can jump only in forward direction.
Example1:-
Let The position of stones be [0,1,3,5,6,8,12,17]
There are a total of 8 stones.
The first stone at the 0th division, second stone at the 1st division, third stone at the 3rd division, and so on...
The last stone at the 17th division.
Output:-Yes
Explanation:-
Shyam can jump to the last stone by jumping 1 division to the 2nd stone, then 2 divisions to the 3rd stone, then 2 divisions to the 4th stone, then 3 divisions to the 6th stone, 4 divisions to the 7th stone, and 5 divisions to the 8th stone.
Example2:-
Let the positions of stones be [0,1,2,3,4,8,9,11]
Output:-No
Explanation:-
There is no way to jump to the last stone as
the gap between the 5th and 6th stone is too large.
Input format:-
Number of stones
Next n lines –positions of n stones
Output format:-
Yes or No
Note:- The first stone is always in the 0th division
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment