Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerEarth Prison Break problem solution

YASH PAL, 31 July 2024
In this HackerEarth Prison Break problem solution Alfie was a prisoner in mythland. Though Alfie was a witty and intelligent guy.He was confident of escaping prison.After few days of observation,He figured out that the prison consists of (N X N) cells.i.e The shape of prison was (N X N) matrix. Few of the cells of the prison contained motion detectors.So Alfie planned that while escaping the prison he will avoid those cells containing motion detectors.Yet before executing his plan,Alfie wants to know the total number of unique possible paths which he can take to escape the prison.Initially Alfie is in cell (1, 1) while the exit of the cell (N, N).
HackerEarth Prison Break problem solution

HackerEarth Prison Break problem solution.

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int cell[20][20],mark[20][20],count_route=0,n;

void route(int i,int j){
if((i==n)&&(j==n)){
count_route++;
return;
}
mark[i][j] = 1;
if( (j+1)<=n && mark[i][j+1] == 0 && cell[i][j+1] == 0 )
route(i,j+1);
if( (i+1)<=n && mark[i+1][j] == 0 && cell[i+1][j] == 0 )
route(i+1,j);
if( (j-1)>=1 && mark[i][j-1] == 0 && cell[i][j-1] == 0 )
route(i,j-1);
if( (i-1)>=1 && mark[i-1][j] == 0 && cell[i-1][j] == 0 )
route(i-1,j);
mark[i][j] = 0;
return;
}

int main()
{
int i,j,t;
cin >> t;
while(t--){
cin >> n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
cin >> cell[i][j];
mark[i][j] = 0;
}
}
count_route = 0;
route(1,1);
cout << count_route << endl;
}
return 0;
}

coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes