Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
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 *

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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