## Best Time to Buy and Sell Stock in Java

The challenge Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to… Read More »Best Time to Buy and Sell Stock in Java

The challenge Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to… Read More »Best Time to Buy and Sell Stock in Java

The challenge Write a method, that will get an integer array as parameter and will process every number from this array.Return a new array with… Read More »How to Solve the “To square(root) or not to square(root)” Challenge in Java

The challenge “A divisibility rule is a shorthand way of determining whether a given integer is divisible by a fixed divisor without performing the division,… Read More »Solving the Rule of Divisibility by 13 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, return false. Swapping letters is defined… Read More »How to Calculate Buddy Strings in Java

The challenge 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 More »How to Flip a Binary Matrix in Java

The challenge 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 between the sum of all left… Read More »How to Tilt 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, the only… Read More »How to solve the House Robber Challenge in Java

The challenge You have an initial power of P, an initial score of 0, and a bag of tokens where tokens[i] is the value of the ith token (0-indexed). Your goal is to maximize your total score by potentially… Read More »How to Solve the Bag of Tokens Challenge in Java

The challenge 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 sum the result… Read More »How to Find the Smallest Divisor Given a Threshold 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