Problem

Check Permutation Divisible by Eight

Learn this problem
HackerRank logoHackerRankFULLTIMEONSITE INTERVIEW

Problem statement

You are given an array of strings numbers. Each string consists of decimal digits.

For each string, determine whether any permutation of its digits can form a number divisible by 8. Return an integer array where the i-th value is 1 if some permutation of numbers[i] is divisible by 8, and 0 otherwise.

A permutation may include leading zeros; the permuted string is interpreted as a decimal number.

Function

checkPermutationDivisibleByEight(numbers: String[]) → int[]

Examples

Example 1

numbers = ["61", "75", "123"]return = [1, 0, 1]

"61" can be permuted to "16", which is divisible by 8. "75" has no valid permutation. "123" can be permuted to "312", which is divisible by 8.

Example 2

numbers = ["8", "10", "1000"]return = [1, 0, 1]

"8" is already divisible by 8. Neither "10" nor "01" is divisible by 8. "1000" is divisible by 8.

Constraints

  • Each string in numbers contains only decimal digits.

More HackerRank problems

drafts saved locally
public int[] checkPermutationDivisibleByEight(String[] numbers) {
  // write your code here
}
numbers["61", "75", "123"]
expected[1, 0, 1]
checking account