Validate Input Against Length Bounds
Updated
Problem statement
For this exercise, validate a text input against a supplied length rule. Return true exactly when the number of characters in text is at least minLength and at most maxLength; otherwise return false.
- Both endpoints are inclusive.
- The text contains only printable ASCII characters. Spaces and punctuation each count as one character.
- Measure the original text without trimming, changing case or interpreting markup.
- The supplied bounds are valid:
0 <= minLength <= maxLength.
This rule checks one input value; no UI framework or event wiring is involved.
Function
validateInputLength(text: String, minLength: int, maxLength: int) → booleanExamples
Example 1
text = "hello"minLength = 3maxLength = 5return = trueThe text has five characters, so it satisfies the inclusive interval from three through five.
Example 2
text = ""minLength = 1maxLength = 4return = falseThe empty text has length zero, below the supplied minimum of one.
Constraints
0 <= text.length <= 10000.- Every text character has an ASCII code from
32through126. 0 <= minLength <= maxLength <= 10000.
More Klaviyo interview questions
- Render Sidebar Labels as HTMLONSITE INTERVIEW · Seen Jul 2025
- Trace Logs at a Two-Second CadenceONSITE INTERVIEW · Seen Jul 2025
- Flatten JSON into Repeated Key-Value PairsONSITE INTERVIEW · Seen Oct 2023
- Conditionally Insert or Update RecordsONSITE INTERVIEW · Seen Jul 2022
- Progressive Parcel Tracking OperationsOA · Seen Aug 2026
- Banking Transfers, Account Merges, and Historical BalancesOA · Seen Jul 2025
- In-Memory Database with Permanent and Expiring ValuesOA · Seen Jul 2025
- File Storage with User Quotas, Merging, Backups, and RestoreOA · Seen Jun 2025
- Key-Value Locks with Waiting QueuesOA · Seen Sep 2024
Similar questions at other companies
- Extract Hashtags from a TweeteBay · ONSITE INTERVIEWeBay interview questions
- 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