This is a verified interview question from Fidelity-investment. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Consecutive Digits - Fidelity investment Online Assessment" covers key patterns like Arrays.
"You are given a string `S` of length `N`. Your task is to find and print the maximum integer present in the string. An integer is defined as a maximal contiguous sequence of digit characters (`0-9`). Any non-digit character separates two integers. ### Notes * Print `-1` if the string contains no integer. * Print `-2` if the string is empty. --- ## Input Format * The first line contains an integer `N`, the length of the string. * The second line contains the string `S`. --- ## Output Format Print a single integer: * The maximum integer present in the string. * `-1` if no integer is found. * `-2` if the string is empty. --- ## Constraints * `1 ≤ N ≤ 100000` * The string may contain uppercase letters, lowercase letters, digits, spaces, and special characters. --- ## Sample Input 1 ```text 39 33 milestone is either 12 or 75 km away ``` ## Sample Output 1 ```text 75 ``` ### Explanation The integers present in the string are `33`, `12`, and `75`. The maximum among them is `75`. --- ## Sample Input 2 ```text 16 abc123xyz456def ``` ## Sample Output 2 ```text 456 ``` --- ## Sample Input 3 ```text 10 hello world ``` ## Sample Output 3 ```text -1 ``` ### Explanation The string contains no digits. --- ## Sample Input 4 ```text 0 ``` ---"
Join thousands of developers practicing for Fidelity-investment.