Accenture OA-9 2024
Problem Description
You are given a string array S that contains the names of some files along with their versions. Your task is to find and return the latest version out of all the files that are correctly named in the array. A file is considered correct if it follows the format of "File_X" where X represents the file version number. Return -1 if there are no correct files in the array.
Note:
- A file is incorrect if the name of the file does not match the format.
- If there is no file in the files array, then also return -1.
Input Format:
- input1: A string array S, representing the names of the files.
- input2: An integer value representing the size of the array.
Output Format:
Return an integer value representing the latest version out of all the files that are correctly named in the array.
Constraints:
- 1 ≤ N ≤ 10^5
- 1 ≤ |S[i]| ≤ 100
Example
Sample Input:
input1: ("File_1", "File_3", "File_2")
input2: 3
Sample Output:
3
Explanation:
In this example, all the files are correctly named, and the latest version is 3. Therefore, the output is 3.