25.09.30 틀림

처음에 트리맵 쓰니 틀림. 트리맵 쓰면 자동으로 키를 정렬하는데 문자열은 알아서 사전순으로 정렬한것. 내가원한건 put순서를 유지하는거였음 순서유지하려면 LinkedHashMap 을 써야했다.

import java.io.BufferedReader;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.util.*;  
  
class Main {  
    public static void main(String[] args) throws IOException {  
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
        Map<String, List<String>> prefixMap = new LinkedHashMap<>();  
        int N = Integer.parseInt(br.readLine());//N^2 = 4억  
        prefixMap.putIfAbsent("", new ArrayList<>());  
        for (int i = 0; i < N; i++) {  
            String word = br.readLine();  
            prefixMap.get("").add(word);  
            for (int j = 1; j <= word.length(); j++) {  
                String s = word.substring(0, j);  
                prefixMap.putIfAbsent(s, new ArrayList<>());  
                prefixMap.get(s).add(word);  
            }  
        }  
  
        //한바퀴 돌면서 길면서 2개이산인거  
        int maxLength = Integer.MIN_VALUE;  
        for (Map.Entry<String, List<String>> set : prefixMap.entrySet()) {  
            if (set.getValue().size() >= 2) {  
                maxLength = Math.max(maxLength, set.getKey().length());  
            }  
        }  
        for (Map.Entry<String, List<String>> set : prefixMap.entrySet()) {  
            if (maxLength == set.getKey().length() && set.getValue().size() >= 2) {  
                System.out.println(set.getValue().get(0));  
                System.out.println(set.getValue().get(1));  
                break;  
            }  
        }  
  
    }  
}