You are viewing a single comment's thread. Return to all comments →
i spent 5-6hrs to write the below code :( . I have a looong way to go
long total = 0; long l = s.length(); List<Integer> aList = new ArrayList<>(); List<Long> lastList = new ArrayList<>(); long totalFullSplits = n/l; long repeatCounter = totalFullSplits * l; for(int i = 0; i < l; i++) if(s.charAt(i) == 'a') { aList.add(i); long lastIdx = 0; lastIdx = ((i+1) + (l * (totalFullSplits - 1))) - 1; if(repeatCounter + (i+1) <= n) lastIdx = (repeatCounter + (i+1)); lastList.add(lastIdx); } for(int i = 0; i < aList.size(); i++) { total += ((lastList.get(i) - aList.get(i)) / l) + 1; } return total;
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
i spent 5-6hrs to write the below code :( . I have a looong way to go