How to Calculate Buddy Strings in Java
The challenge
Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, …
345 articles about java development, tools, and best practices
Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, …
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.
To flip an image …
Read Article →Given the root of a binary tree, return the sum of every tree node’s tilt.
The tilt of a tree node is the absolute difference …
Read Article →You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only …
Read Article →You have an initial power of P, an initial score of ``, and a bag of tokens where tokens[i] is the value of the …
Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and …
You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars) and …
Read Article →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 …
Read Article →Write a function to convert a name into initials. This challenge strictly takes two words with one space in between them.
The output …
Read Article →Sort a linked list using insertion sort.
A graphical example of insertion sort. The partially sorted list (black) initially contains …
Read Article →The goal is to create a function that removes the first and last characters of a string. You don’t have to worry with strings with …
Read Article →There are N children standing in a line. Each child is assigned a rating value.
You are giving candies to these children subjected to …
Read Article →You have n candies, the i<sup>th</sup> candy is of type candies[i].
You want to distribute the candies equally between a …
Read Article →You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the i<sup>th</sup> …
Write a function which takes a number and returns the corresponding ASCII char for that value.
Example:
Ascii.getChar(65) // => …
Read Article →
Can you find the needle in the haystack?
Write a function findNeedle() that takes an array full of junk but containing one …
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 …
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 < …
Replace all vowel to exclamation mark in the sentence. aeiouAEIOU is vowel.
replace("Hi!") === "H!!" …
Read Article →
You are given an array with positive numbers and a number N. You should find the N-th power of the element in the array with the index …
Read Article →Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to …
Read Article →You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at …
Read Article →Given a reference of a node in a connected undirected graph.
Return a deep copy (clone) of the graph. Effectively a graph copy.
Each …
Read Article →Ghost objects are instantiated without any arguments.
Ghost objects are given a random color attribute of white" or …
Read Article →