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

Absolute Permutation.java solution not working #1

Open
javaHelper opened this issue Jun 29, 2021 · 3 comments
Open

Absolute Permutation.java solution not working #1

javaHelper opened this issue Jun 29, 2021 · 3 comments

Comments

@javaHelper
Copy link

No description provided.

@Aabhas99
Copy link
Owner

Can you please provide the description or the test case?

@javaHelper
Copy link
Author

Can u try once on hackerank platform

@javaHelper
Copy link
Author

All test cases are breaking.. here is the code -

public static List<Integer> absolutePermutation(int n, int k) {
        Integer ar[] = new Integer[n];
        try {
            for (int x = 1; x <= n; x++) {
                if (x - k > 0 && ar[x - k - 1] == 0) {
                    ar[x - k - 1] = x;
                } else {
                    ar[x + k - 1] = x;
                }
            }
        } catch (Exception e) {
            Integer q[] = {-1};
            return Arrays.stream(q).collect(Collectors.toList());
        }
        return Arrays.stream(ar).collect(Collectors.toList());
    }

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

2 participants