HackerRank_solutions icon indicating copy to clipboard operation
HackerRank_solutions copied to clipboard

Let's add C++ solutions

Open ghost opened this issue 2 years ago • 3 comments

Hey @RodneyShag, I have saved most of all my Hackerank solutions and I would love to contribute them to this repo for the C++ solutions part. So can you let me know what I should do next?

ghost avatar Aug 28 '21 06:08 ghost

import java.util.*;

public class Solution {

public static boolean canWin(int leap, int[] game) {
    return isSolvable(leap, game, 0);

}
private static boolean isSolvable(int m, int[] arr, int i) { if (i < 0 || arr[i] == 1) return false; if ((i == arr.length - 1) || i + m > arr.length - 1) return true;

arr[i] = 1;
return isSolvable(m, arr, i + 1) || isSolvable(m, arr, i - 1) || isSolvable(m, arr, i + m);

}

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int q = scan.nextInt();
    while (q-- > 0) {
        int n = scan.nextInt();
        int leap = scan.nextInt();
        
        int[] game = new int[n];
        for (int i = 0; i < n; i++) {
            game[i] = scan.nextInt();
        }

        System.out.println( (canWin(leap, game)) ? "YES" : "NO" );
    }
    scan.close();
}

}

BinayakReddy avatar Sep 07 '21 06:09 BinayakReddy

JAVA 8

BinayakReddy avatar Sep 07 '21 06:09 BinayakReddy

@BinayakReddy What is it that you are trying to add?

ghost avatar Sep 07 '21 07:09 ghost