//{ Driver Code Starts import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int tc = Integer.parseInt(br.readLine().trim()); while (tc-- > 0) { String[] inputLine; inputLine = br.readLine().trim().split(" "); int n = Integer.parseInt(inputLine[0]); int m = Integer.parseInt(inputLine[1]); int[] arr = new int[m]; inputLine = br.readLine().trim().split(" "); for (int i = 0; i < m; i++) { arr[i] = Integer.parseInt(inputLine[i]); } Tasks ans = new Solution().findTasks(arr, m, n); for (Integer x : ans.tanya) { System.out.print(x + " "); } System.out.println(); for (Integer x : ans.manya) { System.out.print(x + " "); } System.out.println(); } } } class Tasks { ArrayList<Integer> tanya, manya; Tasks() { tanya = new ArrayList<>(); manya = new ArrayList<>(); } } // } Driver Code Ends // check Tasks class in driver class Solution { Tasks findTasks(int[] arr, int m, int n) { if(arr.length == 0) return new Tasks(); //make a hashmap and store tasks which are already done HashSet<Integer>set = new HashSet<>(); for(int val : arr) set.add(val); //make an object of class Tasks and add answers in its arraylist Tasks t = new Tasks(); int count =0; //for determining if the index is odd or even for(int i = 1 ;i <= n ;i++){ boolean flag = false; if(set.contains(i)) flag = true; if(flag == false){ if(count%2==0) t.tanya.add(i); else t.manya.add(i); count++; } } return t; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter