FastPrepFind Reciprocal
Problems/Find Reciprocal

Find Reciprocal

DTCC logoDTCC● MediumOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an integer N. Write its reciprocal 1/N as a decimal. The decimal always ends in a block of digits that repeats forever. If the decimal ends, the repeating block is 0 (for example, 1/8 = 0.125000...). Use the shortest such block, starting as early as possible.

Return a string made of "0.", then every digit up to and including the first full copy of the repeating block, then a space, then the repeating block once more.

For example, if N = 8, the answer is "0.1250 0". If N = 9, 1/9 = 0.111..., so the answer is "0.1 1".

Function

findReciprocal(N: int) → String

Examples

Example 1

N = 8return = "0.1250 0"

The reciprocal of 8 is 1/8 = 0.12500000..., so the output is 0.1250 0.

Example 2

N = 9return = "0.1 1"

The reciprocal of 9 is 1/9 = 0.111111..., so the output is 0.1 1.

Constraints

  • 2 ≤ N ≤ 10^5

Similar questions at other companies

  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Task Scheduler with CooldownGoDaddy · OA
  • Get Triplet CountIBM · OAIBM interview questions
  • Minimum Anagram PeriodVisa · OAVisa interview questions
  • Maximum Equal Parts for PrefixesAmazon · OA
  • Get Triplet CountPoint72 · OAPoint72 interview questions
  • Minimum Anagram PeriodWells Fargo · OAWells Fargo interview questions
See DTCC hiring insights
Saved
class Solution {
    public String findReciprocal(int N) {
      // write your code here
    }

}
Checking account…