Understand Largest 3-Repeated-Digit Number in a String Problem

Problem: Largest 3-Repeated-Digit Number in a String

You are given a string num that represents a large number. A good number is defined as:

  1. A substring with a length of exactly 3 characters.
  2. All characters in this substring are the same digit.

Your task: Return the largest good number as a string. If there is no such substring, return "" (an empty string).


Additional Notes:

  • A substring is a sequence of consecutive characters within the string.
  • Leading zeroes are allowed in a good number.

Examples:

Example 1
Input: num = "6777133339"
Output: "777"

Example 2
Input: num = "2300019"
Output: "000"

Example 3
Input: num = "42352338"
Output: ""


Constraints:

  • 3 <= num.length <= 1000
  • num consists only of digits 0-9
Category:
  • Leetcode Problem of the Day
  • Strings
Programming Language:
  • Java
Reference Link:

https://drawtocode.vercel.app/problems/largest-3-repeated-digit-number-in-a-string

Online IDE

Scroll down for output
Java
Output:

Loading component...

Loading component...