You are viewing a single comment's thread. Return to all comments →
Java
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bufferedReader.readLine().trim()); int max = 0; int count = 0; ArrayList <Integer> binary = new ArrayList<>(); while (n>0) { int remainder = n%2; n=n/2; binary.add(remainder); } for(int i = 0; i<binary.size();i++) { int position = binary.get(i); if(position == 1) { count++; max = Math.max(count, max); } else { count = 0; } } System.out.println(max); bufferedReader.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
Java