Return the largest digit in a number

Beginner Problems Basic Maths Easy
  • This concept is used widely in validation of inputs or entities in software applications
  • In banking software or financial applications, you may sometimes have to validate credit card numbers, account numbers, or other numeric inputs where identifying and manipulating the largest digit could be part of the process
  • Similarly, in gaming and sports applications, stats and scores often involve working with largest digits for comparison and ranking purposes

You are given an integer n. Return the largest digit present in the number.

Examples:

Input: n = 25

Output: 5

Explanation: The largest digit in 25 is 5.

Input: n = 99

Output: 9

Explanation: The largest digit in 99 is 9.

Input: n = 1

Constraints

  • 0 <= n <= 5000
  • n will contain no leading zeroes except when it is 0 itself.

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree