You are viewing a single comment's thread. Return to all comments →
3 cases are getting failed for this code due to time complexity, import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int userInt = sc.nextInt(); ArrayList<Long> s = new ArrayList<Long>(); for(int i=0; i<userInt; i++) { char c = sc.next().charAt(0); Long n = sc.nextLong(); if(c == 'a') { if(s.isEmpty() || s.get(s.size()-1)<n ) {s.add(n);} else { for(int j = 0; j<s.size(); j++) { if(s.get(j)<n) { continue; } else { s.add(j, n); break; }}}} else if(c == 'r' && s.contains(n)) {s.remove(n);} else if (c == 'r' && s.contains(n) == false) { System.out.println("Wrong!"); continue; } if (s.isEmpty()) { System.out.println("Wrong!"); continue; } if(s.size()%2==0) { Long a = (s.get(s.size()/2)+s.get((s.size()/2)-1)); double k = a.doubleValue(); if ((k/2)%1 != 0) { System.out.println(String.format("%.1f", k/2)); } else { System.out.println(a/2);}} else {System.out.println(s.get(s.size()/2));} }}}
Seems like cookies are disabled on this browser, please enable them to open this website
Median Updates
You are viewing a single comment's thread. Return to all comments →
3 cases are getting failed for this code due to time complexity, import java.io.; import java.util.;
public class Solution {