Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5358 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@anishrajan | 505 |

@thanosagain | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

Given a non-negative integer **N**, repeatedly add all its digits until the result has only one digit.

**Example 1:**

Input:N = 98Output:8Explanation:Sum of digit of N = 98 is 9 + 8 = 17 Sum of digit of 17 = 1 + 7 = 8 Since 8 is the single digit number hence it is the required answer.

**Example 2:**

Input:N = 1Output:1Explanation:Since 1 is the single-digit number hence it is the required answer.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **singleDigit()** which takes an integer N as an input parameter and return the single-digit you will get after repeatedly adding the digits of N.

**Expected Time Complexity:** O(1)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N <= 10^{18}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Repetitive Addition Of Digits

...