Accenture Campus Coding Question – File Version

📖 Problem Statement

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 an integer value representing 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:

File_X

(where X represents the file version number).

Return -1 if there are no correct files in the array.

🔹 Notes:

A file is incorrect if the name of the file does not match the required format.

If there is no file in the array, also return -1.

🔹 Input Specification

input1 : A string array S, representing the names of the files.

input2 : An integer value representing the size of the array.

🔹 Output Specification

Return an integer value representing the latest version out of all the files that are correctly named in the array.

🔹 Examples
Example 1
Input:
input1 = ["File_1", "File_3", "File_2"]
input2 = 3

Output:
3

Explanation:
The file array is ["File_1", "File_3", "File_2"].
All are valid. The maximum version is 3, so the output is 3.

Example 2
Input:
input1 = []
input2 = 0

Output:
-1

Explanation:
The file array is empty. Hence, return -1.

Comments (0)