Posts

A/B Testing

Problem statement : Write AB testing logic in java, which can route to branches based on the percentage given. Example : A 25  B 75 In this case, 25% of traffic has to go to "A" and 75% to "B" Solution: Step 1: Find GCD of the percentages 25 and 75. GCD is 25 Divide them by the GCD which results in 1 and 3 is the converted percentage. Step 2: Build request lookup map for the sum of converted percentage. Have a counter map for each branches, for each request the selected lowest percentage branch counter will be incremented. Request Count             Counter Map             Converted Percentage         Lowest Percentage                                          A           B                    A(1)...

Longest Palindrome length in sub-array with rearrange

Problem statement : Find the longest even palindrome length of the sub array from the given string of digits. The palindrome can be formed by rearranging the characters as well. Example : Given a string "1234535498" The palindrome formed can be 345543 and the length is 6. My Solution: Create a boolean array which will be true if it can form a palindrome. Find the contiguous boolean subarray with maximum number of true values. If the length is odd rerun the same with the subarray. Comments are welcome to provide a better solution or evaluate this solution. Algorithm: Iterate through the input string character by character. For each character, have a counter and increment it for each loop. Check if the character is present in the character array and get the last index of it. if the last index is not of -1, insert true in the boolean array for the last index and the counter. finally insert the character to the character array for the counter. After the...