FastPrepValidate Ada Integer Literal
Problems/Validate Ada Integer Literal

Validate Ada Integer Literal

eBay logoeBay● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This comes from the second round of a four-round eBay Software Engineer loop that ended in an offer. The round was live coding. The task was to check if a string is an Ada-style integer: either plain decimal digits, or a base from 2 to 16, then digits of that base between two # signs. Underscores may be mixed in and are skipped. The report gives three short examples, and we keep all three.

It does not say where underscores may go, whether leading zeros or a sign are allowed, what may follow the closing #, how long the string can be, or what the function looks like. We remove every underscore before checking, allow leading zeros, allow no sign, decimal point, exponent or text after the closing #, chose the limits (1 to 100 characters) and the function, and added one example of our own.

Our version is about 90% the same as the reported question.

In the Ada programming language, an integer can be written in two forms. Given a string s, return true if s is a valid integer in one of these forms, and false otherwise.

Underscores _ are only separators: they may appear anywhere in s, any number of times, and are ignored. So first remove every underscore. The string that is left must have one of these two forms:

  • Decimal form: one or more decimal digits 0 to 9, such as 2024.
  • Based form: base#digits#. The base part is one or more decimal digits 0 to 9, and its value must be from 2 to 16. The digits part is one or more digits of that base. The characters 0 to 9 stand for the values 0 to 9, and a to f or A to F stand for 10 to 15. The value of each digit must be less than the base. Both # signs are required, and nothing may come after the second one.

Leading zeros are allowed in both parts, so 007 and 016#ff# are valid. Nothing else is allowed: there is no sign, decimal point or exponent, so strings such as -5, 1.5 and 1e6 are not valid.

Function

isValidAdaInteger(s: String) → boolean

Examples

Example 1

s = "123_456_789"return = true

Removing the underscores leaves 123456789. It has no # and every character is a decimal digit, so it is a valid number in decimal form and the answer is true.

Example 2

s = "16#123abc#"return = true

This is the based form with base 16. Between the two # signs, 1, 2 and 3 have the values 1 to 3, and a, b and c have the values 10, 11 and 12. Every value is less than 16, so the answer is true.

Example 3

s = "10#123abc#"return = false

The base is 10, so the value of each digit must be less than 10. 1, 2 and 3 pass, but a, b and c have the values 10, 11 and 12, which are not less than 10. So the answer is false.

Example 4

s = "8#1_7_8#"return = false

Removing the underscores leaves 8#178#, so the base is 8 and each digit must be at most 7. 1 and 7 pass, but the last digit 8 equals the base, so the answer is false.

Constraints

  • 1 <= s.length <= 100
  • s consists of English letters, digits and the characters '_', '#', '+', '-' and '.'.

More eBay Onsite Interview questions

  • Extract Hashtags from a TweetONSITE INTERVIEW · Seen Nov 2026
  • Count Distinct Pairs With Sum KONSITE INTERVIEW · Seen Nov 2026
  • Diameter of Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Count Staircases with Strictly Increasing StepsONSITE INTERVIEW · Seen Oct 2026
  • Hierarchical Permission CheckONSITE INTERVIEW · Seen Oct 2026
  • Matrix MultiplicationONSITE INTERVIEW · Seen Oct 2026
  • N-Queens Solution CountONSITE INTERVIEW · Seen Oct 2026
  • Gas StationONSITE INTERVIEW · Seen Oct 2026
  • Onion-Peel Layers of a Binary TreeONSITE INTERVIEW · Seen Oct 2026
  • Container With Most WaterONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
  • Christmas Tree with N TiersVerily · ONSITE INTERVIEW
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
  • Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
  • Implement tail -nConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
All eBay interview questionsSee eBay hiring insights
Saved
class Solution {
    public boolean isValidAdaInteger(String s) {
        // Write your code here.
    }
}
Checking account…