Now you are given a string S, which represents a software license key which we would like to format. The string S is composed of alphanumerical characters and dashes. The dashes split the alphanumerical characters within the string into groups. (i.e. if there are M dashes, the string is split into M+1 groups). The dashes […]

## Frontend interview questions

Questions you may get asked: 10 Interview Questions Every JavaScript Developer Should Know Front-End Job Interview Questions Front End Web Development Quiz Interview Questions for Front-End-Developer JavaScript Web Quiz Questions you ask: An open source list of developer questions to ask prospective employers Preparing: Preparing for a Front-End Web Development Interview in 2017 Interview Cake — […]

## Why is String immutable in java?

This question has been asked in a number of interviews in the past and is still being asked. If you search google for this question you will find people trying to answer this question. But no one has been able to answer it properly and no one except the Java designers can really answer. We […]

## Predict the Winner -Leetcode

Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a number, that number will not be available for the next player. This continues until all […]

## Leetcode – Zuma Game

Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand. Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if there is […]

## Number Complement – Leetcode

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: The given integer is guaranteed to fit within the range of a 32-bit signed integer. You could assume no leading zero bit in the integer’s binary representation. Example 1:

1 2 3 |
Input: 5 Output: 2 Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2. |

Example 2:

1 2 3 |
Input: 1 Output: 0 Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0. |

[…]

## Max Consecutive Ones – Leetcode

Given a binary array, find the maximum number of consecutive 1s in this array. Example 1:

1 2 3 4 |
Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. |

Note: The input array will only contain 0 and 1. The length of input array is a positive integer and will not exceed 10,000 Solution This is an easy to solve problem. We keep on counting the ones till a […]

## Construct the Rectangle Leetcode

Given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

1 2 3 4 5 |
1. The area of the rectangular web page you designed must equal to the given target area. 2. The width W should not be larger than the length L, which means L >= W. 3. The difference between length L and width W should be as small as possible. |

You need to output the length L and the width W of the web page you designed in sequence. Example:

1 2 3 4 |
Input: 4 Output: [2, 2] Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4,1]. But according to requirement 2, [1,4] is illegal; according to requirement 3, [4,1] is not optimal compared to [2,2]. So the length L is 2, and the width W is 2. |

Note: The given area […]

## How to find a word inside a folder recursively in linux?

This can be done using grep command.

1 |
grep -nr 'searchstring' /yourdirectory |

If you are searching in current directory use dot(.) as shown below

1 |
grep -nr 'searchstring' . |

Options we have used -n : Show relative line number in the file -r : Recursively […]

## Unsupported major.minor version 52.0

Recently we migrated to Java 8 from Java 7. And after installing Java 8 on my system, running any test threw the exception

1 |
Unsupported major.minor version 52.0 |

And the solution for me was to run Maven > Update Project from context menu. You can also update the classpath of your project from command line using the following command […]