FastPrepCheck Permutation Divisible by Eight
Problems/Check Permutation Divisible by Eight

Check Permutation Divisible by Eight

HackerRank logoHackerRankFULLTIMEONSITE INTERVIEW

Updated Jul 2026

QuestionFunctionExamplesConstraints

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 interview questions

  • Classify Password StrengthPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Ball Passing at Time KPHONE SCREEN · Seen Dec 2025
  • Longest Equal Binary SubarrayOA · Seen Dec 2025
  • Longest Equal Binary Subarray After One FlipOA · Seen Dec 2025
  • Longest Prefix-Valid Binary SubarrayOA · Seen May 2025
All HackerRank interview questionsSee HackerRank hiring insights
Saved
class Solution {
    public int[] checkPermutationDivisibleByEight(String[] numbers) {
      // write your code here
    }
}
Checking account…