본문 바로가기
CodeSignal/Arcade

CodeSignal [57/60] fileNaming

by 벤진[Benzene] 2020. 5. 28.

Problem:

You are given an array of desired filenames in the order of their creation. Since two files cannot have equal names, the one which comes later will have an addition to its name in a form of (k), where k is the smallest positive integer such that the obtained name is not used yet.

Return an array of names that will be given to the files.

 

Example

For names = ["doc", "doc", "image", "doc(1)", "doc"], the output should be
fileNaming(names) = ["doc", "doc(1)", "image", "doc(1)(1)", "doc(2)"].

 

-Summary-

1. Check if the current index of item is previously in the list.

2. If the name wasn't in the previous index of the list, keep continuing

   If name was in the previous index of the list, increase the count until "name(#)" format does not exist in the list. (Ex. name(1), name(2), name(3)...etc)

3. Once we found the "name(#)" format does not exist in the previous index of the list, replace "name(#)" with a current index.

4. Return list

 

모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]

https://codesignal.com/

'CodeSignal > Arcade' 카테고리의 다른 글

CodeSignal [59/60] spiralNumbers  (0) 2020.05.28
CodeSignal [58/60] messageFromBinaryCode  (0) 2020.05.28
CodeSignal [56/60] digitsProduct  (0) 2020.05.28
CodeSignal [55/60] differentSquares  (0) 2020.05.28
CodeSignal [54/60] sumUpNumbers  (0) 2020.05.28

댓글