Posts5 Really interesting (functional) solution to counting duplicates Not necessary, but just cool. import java.util.Map; import static java.util.function.Function.identity; import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.groupingBy; class CountingDuplicates { private static Map charFrequenciesMap(final String text) { return text.codePoints() .map(Character::toLowerCase) .mapToObj(c -> (char) c) .collect(groupingBy(ide.. 2021. 1. 9. Sorting opens the way Sorting is perhaps a very intuitive and easy ways to do certain stuff, that we might as well consider them as one of the legitimate pattern to solve a problem. There are two notable (string related) questions that I encountered in which we can go about solving the problem using sort. Here's how string can be sorted (just in case you aren't familiar with it) import java.util.Arrays; public class .. 2020. 12. 30. <Check then Change> pattern (Unique string problem, uses bit vector) One of the very first Cracking The Coding Interview question is to write a function that checks if a string is made up of totally unique characters. public void isUniqueString(String str){ boolean record = new boolean[128]; for(int i = 0; i 2020. 12. 30. How to 'onion' into NxN array? This concept arises when you are trying to rotate an N by N square array. Pretty weird at the start. There are mainly two difficult parts to writing an algorithm for this. 1. How do you put top left element to top right element, top right element to bottom right element, bottom right element to bottom left element, bottom left element to top left element - all of them all at once? 2. How do you .. 2020. 12. 26. Concatenation using string builder String s1 = "hello "; String s2 = "world"; String s3 = s1+s2; It may surprise you that the above operation is an O(n) process. This is because the process of 'adding two strings' is actually copying each character into a new array. // this process takes O(s1.length() + s2.length()) or O(max(s1.length(),s2.length())) public String concatenate(String s1, String s2){ // some operation to create a b.. 2020. 12. 26. 이전 1 다음