Join Regular Classroom : Visit ClassroomTech

Nagarro Question Solved | Jump to Escape Jail | Codewindow.in

Hot Topics

Company Based – Codewindow

Interview Questions
1. TCS Technical Questions
2. CTS Technical Questions
3. Infosys Technical Questions
4. Capgemini Technical Questions
5. IBM Technical Questions
6. Wipro Technical Questions
7. Accenture Technical Questions
8. Deloitte Technical Questions
9. MindTree Technical Questions
10. NTT Data Technical Questions
11. Persistent Technical Questions
12. Hexaware Technical Questions
13. ZOHO Technical Questions
14. HCL Technical Questions
15. Genpact Technical Questions
16. udostres Technical Questions
17. samsung research Technical Questions
18. Media.net Technical Questions
19. Tejas Network Technical Questions
20. Kantar Technical Questions
21. Itron Technical Questions
22. Fractal Analyst Technical Questions
23. Lexmark International Technical Questions
24. Infeneon Technologies Technical Questions
25. Razorpay Technical Questions
26. payu Technical Questions
27. Navi Technical Questions
28. Tata Cliq Technical Questions
29. Grab Technical Questions
30. Schlumberger Technical Questions
31. Latenview Analytics Technical Questions
32. GreayB Technical Questions
33. Tally solution Technical Questions
34. Amagi Technical Questions
35. HFCL Technical Questions
36. Slice Technical Questions
37. Larsen & Turbo Technical Questions
38. Zenser Technical Questions
39. Siemens Technical Questions
40. Exon Movie Technical Questions
41. Gupshup Technical Questions
42. Smart cube Technical Questions
43. Celebal Tech Technical Questions
44. Teg Analytics Technical Questions
45. Commvault Systems Technical Questions
46. Incuture Technical Questions
47. Tiger Technical Questions
48. Bridgei2i Technical Questions
49. code nation Technical Questions
50. DE Show Technical Questions
51. Amazon Technical Questions
52. Flipkart Technical Questions
53. Morgan Stanly Technical Questions
54. duutsche bank Technical Questions
55. textas Technical Questions
56. pwc Technical Questions
57. salesforce Technical Questions
58. optum Technical Questions
59. Nvidia Technical Questions
60. Itc Infotech Technical Questions
61. linkedin Technical Questions
62. Adobe Technical Questions

Nagarro Question Solved | Jump to Escape Jail | Codewindow.in

Question:

A thief, jack Sparrow plans to escape from jail. He , being a monkey man, can jump over a wall. jack has practiced well and succeeds in jumping X meters. 

However, the wall is slippery, so he slides down Y meters after every jump. To escape from jail, he must cross N number of walls, where the height of each wall is given in an array.

Your task is to return the total number of jumps Jack needs to make to escape from the jail.

 

Input Specification:

Input 1: An integer value X denoting the number of meters he can jump up(1<=input1<=10^4)

Input 2: An integer value Y denoting  the number of meters he slides down (1<=input2<=10^4)

Input 3: An integer value N denoting the number of walls he needs to jump to escape(1<=input3<=10^4)

Input 4: An integer array of size N representing the height of each wall where(1<=input4[i]<=1000)

 

Output Specifications:

Return an integer value representing the total number of jumps Jack Sparrow must make in order to escape from the jail.

 

Example 1:

input1: 10

input2: 1

input3: 1

input4: 10

Output: 1

Explanation:

Here, Jack Sparrow can jump a height of 10 meters but slides down by 1 meter.

He was 1 wall to jump, and the height of the wall is 10 meters.

Since he jumps 10 meters in the first attempt, he crosses the wall easily in the first attempt itself.

Therefore, 1 is returned as the output.

Example 2:

Input1: 5

Input2: 1

Input3: 2

Input4: 9 10

Output: 5

Explanation:

Here, Jack Sparrow can jump a height of 5 meters but slides down by 1 meters.

He was 2 walls to jump and the height of each wall is 9 and 10 meters respectively.

First wall

Jack makes 2 attempt because at the first attempt he jumps 5 meters nut slides down by

1 meter and does not cross the wall.

In the next attempt he jumps 5 more meters from that position and this time he

does not slide down and crosses the wall in this attempt(4+5=9)

 

Input:

10
1
1
10

Output:

1

Input:

5
1
2
9 10

Output:

5

Python

#https://codewindow.in
#join our telegram channel @codewindow

def calculateTime(X, Y, n, walls):
    jumps = 0
    for i in range(0, n):
        reach = X
        jump = 1
        while reach < walls[i]:
            reach += (X-Y)
            jump += 1
        jumps += jump
    return jumps;        
    

X = int(input())
Y = int(input())
n = int(input())
walls = list(map(int, input().split(" ")))
print(calculateTime(X, Y, n, walls))

C++

//https://codewindow.in
//join our telegram channel @codewindow

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int calculateJumps(int X, int Y, int n, int walls[])
{
    int jumps = 0;
    for(int i=0;i<n;i++) {
        int reach = X;
        int jump = 1;
        while(reach < walls[i]) {
            reach += (X-Y);
            jump += 1;
        }
        jumps += jump;
    }
    return jumps;
}

int main()
{
    int X;
    cin >> X;
    int Y;
    cin >> Y;
    int n;
    cin >> n;
    int walls[n];
    for(int i=0;i<n;i++)
        cin >> walls[i];
    cout << calculateJumps(X, Y, n, walls);
    return 0;
}

JAVA

//https://codewindow.in
//join our telegram channel @codewindow

import java.util.*;
import java.lang.*;
import java.io.*;

class CodeWindow
{
    static int calculateJumps(int X, int Y, int n, int walls[])
    {
        int jumps = 0;
        for(int i=0;i<n;i++) {
            int reach = X;
            int jump = 1;
            while(reach < walls[i]) {
                reach += (X-Y);
                jump += 1;
            }
            jumps += jump;
        }
        return jumps;
    }

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int n = sc.nextInt();
        int walls[] = new int[n];
        for(int i=0;i<n;i++)
            walls[i] = sc.nextInt();
        System.out.println(calculateJumps(X, Y, n, walls));
    }
}

Nagarro Solved

Automata Fixing

      

Popular Category

Hot Topics

Company Based – Codewindow

Interview Questions
1. TCS Technical Questions
2. CTS Technical Questions
3. Infosys Technical Questions
4. Capgemini Technical Questions
5. IBM Technical Questions
6. Wipro Technical Questions
7. Accenture Technical Questions
8. Deloitte Technical Questions
9. MindTree Technical Questions
10. NTT Data Technical Questions
11. Persistent Technical Questions
12. Hexaware Technical Questions
13. ZOHO Technical Questions
14. HCL Technical Questions
15. Genpact Technical Questions
16. udostres Technical Questions
17. samsung research Technical Questions
18. Media.net Technical Questions
19. Tejas Network Technical Questions
20. Kantar Technical Questions
21. Itron Technical Questions
22. Fractal Analyst Technical Questions
23. Lexmark International Technical Questions
24. Infeneon Technologies Technical Questions
25. Razorpay Technical Questions
26. payu Technical Questions
27. Navi Technical Questions
28. Tata Cliq Technical Questions
29. Grab Technical Questions
30. Schlumberger Technical Questions
31. Latenview Analytics Technical Questions
32. GreayB Technical Questions
33. Tally solution Technical Questions
34. Amagi Technical Questions
35. HFCL Technical Questions
36. Slice Technical Questions
37. Larsen & Turbo Technical Questions
38. Zenser Technical Questions
39. Siemens Technical Questions
40. Exon Movie Technical Questions
41. Gupshup Technical Questions
42. Smart cube Technical Questions
43. Celebal Tech Technical Questions
44. Teg Analytics Technical Questions
45. Commvault Systems Technical Questions
46. Incuture Technical Questions
47. Tiger Technical Questions
48. Bridgei2i Technical Questions
49. code nation Technical Questions
50. DE Show Technical Questions
51. Amazon Technical Questions
52. Flipkart Technical Questions
53. Morgan Stanly Technical Questions
54. duutsche bank Technical Questions
55. textas Technical Questions
56. pwc Technical Questions
57. salesforce Technical Questions
58. optum Technical Questions
59. Nvidia Technical Questions
60. Itc Infotech Technical Questions
61. linkedin Technical Questions
62. Adobe Technical Questions

We Love to Support you

Go through our study material. Your Job is awaiting.

Recent Posts
Categories