## [Hackerrank] – Palindrome Index

Question: Given a string, identify the index of character to be removed to change the string into a palindrome. If the string cannot be converted to palindrome or is already a palindrome just return -1. Input: abckdeedcba Output: 3 (0 based indexing) To start off with the problem, we must first understand that there can be two possible… Read More »

## [Hackerrank] – Weighted Uniform Strings

Let us try to simplify the problem as much as we can. We are given with some of the terms. Weights:- According to the problem each character in the English alphabet has been assigned a weight. ‘a’ has been given a weight of 1, ‘b’ has a weight of 2, and so on. The weight of ‘z’ is… Read More »

## Pangrams

Question: Given a string, identify if it is a pangram. Input: The quick brown fox jumps over the lazy little dog. Output: pangram To start with the problem statement we must first understand what is a pangram. A pangram is a string that contains all the characters in the English alphabet at-least once. This means that the string… Read More »

## [Hackerrank] – Two Characters

A string is said to be valid when it has only distinct characters and none of them repeat simultaneously. For example, if string ‘s two distinct characters are x and y, then valid examples could be xyxyx or yxyxy but not xxyy or xyyx. Question: Given a sample string, we need to determine what is the maximum length… Read More »

## [Hackerrank] – Camel Case

Question: Given a camelCase string, find the number of words in the string. Input: saveChangesInTheEditor Output: 5 Camel case is a very popular style of naming variables and methods in most of the programming languages. Not only it helps to make the code readable but also ensures that the variable names are unique and easy to remember. A… Read More »

## Next lexicographic string permutation

Question: Given a string, find the next lexicographic permutation. Input: abc Output: acb First of all let us try to understand what do you mean by next lexicographic string. To get a hold of the concept try to remember an English dictionary and how words are arranged in it. We start with the letter ‘a’, write all the… Read More »

## Kth largest element in an array (Method 1)

Question: Given an unsorted array of integers and a number ‘k’. Return the kth largest element in the array. Input: arr = {3,2,1,5,6,4}, k = 2 Output: 5 Given an unsorted array of integers, you need to determine the kth largest element. By taking a first glance at the problem we can be sure of one thing. If… Read More »

## Convert a number into a string of words

Question: Given an integer N, convert it into a string of words. Input: N = 345 Output: three hundred forty five This is one of the most common problems that we come across in out daily lives. We need to input a number from the user and print it in words. First, we perform a number of checks… Read More »

## Common String Algorithms

In this post, I would try to implement the following string-related algorithm questions. I would like to implement these using Java and try to make additional comments which I think that are useful for understanding the implementations of some type of data structures in Java programming language. Non Repeated Characters in String : Return the unique characters in… Read More »

## Find the first N prime numbers. (Method 3)

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25 Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 We discussed the basic approaches to find the first N prime numbers in these posts Find the first N prime numbers (Method 1) Find the first N prime… Read More »