Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let's add C++ solutions #39

Open
ghost opened this issue Aug 28, 2021 · 3 comments
Open

Let's add C++ solutions #39

ghost opened this issue Aug 28, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 28, 2021

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?

@BinayakReddy
Copy link

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
Copy link

JAVA 8

@ghost
Copy link
Author

ghost commented Sep 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant