Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Hackerrank Find Digits problem solution

YASH PAL, 31 July 202430 November 2025

In this Hackerrank Find Digits problem we have given an integer, and for each digit that makes up the integer determine whether it is a divisor or not and we need to count the number of divisors that occur within the integer.

Hackerrank Find Digits Problem solution in Python.

T = int(input())


for t in range(T):
    i_value = int(input())
    c_value = [float(i) for i in str(i_value)]
    
    total = 0
    for c in c_value:
        if c == 0:
            continue
        if (i_value/c)%1 == 0:
            total += 1
    print(total)

Find Digits solution in Java.

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

class Result {

    /*
     * Complete the 'findDigits' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts INTEGER n as parameter.
     */

    public static int findDigits(int n) {
    // Write your code here
int r = n;
int count = 0;
while(r > 0){
    if(r % 10 != 0 && n % (r % 10) == 0) count++;
    r = r / 10;
}
return count;

    }

}

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int t = Integer.parseInt(bufferedReader.readLine().trim());

        IntStream.range(0, t).forEach(tItr -> {
            try {
                int n = Integer.parseInt(bufferedReader.readLine().trim());

                int result = Result.findDigits(n);

                bufferedWriter.write(String.valueOf(result));
                bufferedWriter.newLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });

        bufferedReader.close();
        bufferedWriter.close();
    }
}

Problem solution in C++ programming.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

void solve() {
    int n;
    cin >> n;
    int nr = n;
    int counter = 0;
    while (nr > 0) {
        int c = nr % 10;
        nr = nr / 10;
        if (c != 0 && n % c == 0) {
            ++counter;
        }
    }
    cout << counter << endl;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    return 0;
}

Problem solution in C programming.

#include <stdio.h>
int main()
{
    int i,t;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
       unsigned long long n,n2;
       int i=0,term;
       scanf("%llu",&n);
       n2 = n;
       while(n2 > 0)
       {
           term = n2%10;
           if(term!= 0 && n%term==0) i++;
           n2 /= 10;
       }
       printf("%dn",i);
    }
    return 0;
}

Problem solution in JavaScript programming.

function processData(numbers) {
  var numbers = numbers.split('n');
  numbers.shift();
  
  var divs = numbers.map(function(n) {
    var count = 0;
    n.split('').forEach(function(d) {
      if(n%d === 0) {
        count++;
      }
    });
    return count;
  });
  
  console.log(divs.join('n'));
  
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes