## How to Sort and Star a String Array in Java

The challenge You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars)… Read More »How to Sort and Star a String Array in Java

The challenge You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars)… Read More »How to Sort and Star a String Array in Java

The challenge Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character. Return the power of… Read More »How to Count Consecutive Characters in Java

The challenge Write a function to convert a name into initials. This challenge strictly takes two words with one space in between them. The output… Read More »How to Abbreviate a Two Word Name in Java

The challenge Sort a linked list using insertion sort. A graphical example of insertion sort. The partially sorted list (black) initially contains only the first… Read More »How to Sort a Linked List using Insertion Sort in Java

The challenge The goal is to create a function that removes the first and last characters of a string. You don’t have to worry with… Read More »How to Remove First and Last Character in a String in Java

The challenge There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the… Read More »How to Distribute Halloween Candies by Rating Value in Java

The challenge You have n candies, the ith candy is of type candies[i]. You want to distribute the candies equally between a sister and a brother so that each of… Read More »How to Distribute Halloween Candies in Java

The challenge You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).… Read More »How to Solve the Maximize Distance to Closest Person Challenge in Java

The challenge Write a function which takes a number and returns the corresponding ASCII char for that value. Example: For ASCII table, you can refer… Read More »How to Get Character from ASCII Value in Java

The challenge Can you find the needle in the haystack? Write a function findNeedle() that takes an array full of junk but containing one “needle” After your function finds the… Read More »Finding a Needle in a Haystack in Java

The challenge We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup (250ml)… Read More »How to Solve the Champagne Tower in Java

The challenge Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132… Read More »How to Solve the 132 Pattern in Java

The challenge Replace all vowel to exclamation mark in the sentence. aeiouAEIOU is vowel. Examples The solution in Java code We could use a StringBuilder and a… Read More »How to Replace all Vowels in a String in Java

The challenge You are given an array with positive numbers and a number N. You should find the N-th power of the element in the… Read More »How to Get the N-th Power in Java

The challenge Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root… Read More »How to Count the Minimum Depth of a Binary Tree in Java

The challenge You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses… Read More »How to Solve the House Robber II Challenge in Java

The challenge Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a val… Read More »How to Clone a Graph in Java

The challenge Ghost objects are instantiated without any arguments. Ghost objects are given a random color attribute of white” or “yellow” or “purple” or “red”… Read More »How to Return Random Values in Java

The challenge Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character. The . character does not… Read More »How to Compare Version Numbers in Java

The challenge Create a method take that accepts a list/array and a number n, and returns a list/array array of the first n elements from the list/array. If you need… Read More »How to Return the First N Elements in Java

The challenge Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row… Read More »How to Search a 2d Matrix/Array in Java

The challenge Write a function that returns the total surface area and volume of a box as an array: [area, volume] The solution in Java We… Read More »Calculate the Surface Area and Volume of a Box with Java

The challenge Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array… Read More »Find Numbers which are Divisible by given Number in Java

There comes a time when you need to split out a subdirectory into it’s own git repo. This is a very simple task if you… Read More »How to Split a Subdirectory to a New Git Repository and Keep the History

The challenge Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where… Read More »Get the Maximum XOR of Two Numbers in an Array in Java