Cisco Systems Interview Question for Software Developers

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
of 0 vote

package com.home.careercup;

public class GreatJailEscape {

    public static void main(String[] args) {
        System.out.println(countJumps(7, 5,2,7,8,9,12,13,14,15));
        System.out.println(countJumps(7, 5,2,4,4,4,4,4,4,4));

    if up (x) <= down (y) then escape is possible if all the walls are of height <= up.
    Also, after scaling a wall successfully - a jump may be required to jump down the wall.
    This jump is not added to this count
    static int countJumps (int N, int up, int down, int ...walls){
        if ( up <= down) {
            //verify if all walls have heights <=up
            for (int i = 0; i <walls.length ; i++) {
                if  (walls [i] > up) throw new RuntimeException("no escape");
            return N; /* N should be same as walls.length */

        int jumps = 0;
        for (int i = 0; i <N ; i++)
            jumps+=jumpcount (walls [i], up, down);
        return jumps;

    /* it my be possible to simplify the below using Math.ceil */
    static int jumpcount ( int h, int up, int down){
        int j;
        if (h<= up) {
            j= 1;
        }else {
            j= h / (up-down) + (h% (up-down) > 0 ? 1 :0);
        System.out.printf("wall height=%d, up=%d, down=%d, jumps=%d %n", h, up, down, j);
        return j;


- Makarand September 04, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Actual jump count is

(h1+h2+h3+h4+..+hn) / (x-y)

- Narayanan September 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

(h1-x)/(x-y)+1+(h2-x)/(x-y)+1...+(hn-x)/(x-y)+1 or

If one can jump from top of one wall to next wall by x feet, things would change though

- Srinivasa Goda October 09, 2018 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More