Weighted Job Scheduling in JAVA
You receive a list of jobs that have three elements: start time, finish time and profit. You have to schedule the jobs with no...
You receive a list of jobs that have three elements: start time, finish time and profit. You have to schedule the jobs with no...
A non-decreasing number has every digit greater than or equal to the previous digit. Given the number of digits, find how many numbers...
You can use a board that is 2 x n size. The tiles are of size 2 x 1. Count the number of ways to tile the board. Tiles can be placed...
Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with the sum equal to the given...
Given two strings as input, the task is to find the length of the shortest string that has both strings as subsequences. Solution: 1. ...
Starting from a string, we determine it’s a palindrome partitioning by diving it into substrings, each being a palindrome. In our problem...
We use a mobile numeric keyboard. You can only press buttons that are up, left, right or down to the current button. You are not allowed...
Starting from a number, we must return the minimum number of square numbers whose sum equals to that number. Solution: 1. static int...
We start from an array of integers, where each number means how many steps can be made from that position. First, we are on index 0 of...
We have as an input a grid of cells with numbers. The numbers can be 0, positive or negative. To move across a cell, we must have...
You must find the minimum cost triangulation of a convex polygon. A triangulation is formed by drawing diagonals between nonadjacent...
Given a 2D array, find the maximum sum submatrix in it. Solution: 1. private static int maximumSumRectangle(int[][] matrix) { 2. ...
You are given an array of positive integers. You must write a program that will return the sum of the maximum sum subsequence of the...
A person buys shares in the morning and sells them in the same day. He can make maximum two transactions of this type in a day. The...
You receive as input n pairs of numbers. In every pair, the first number is smaller than the second one. A chain of pairs (a, b), (c, d)...
Starting from a string, we have to find the longest substring which is a palindrome. Solution: 1. static String...
Given a sequence of letters, find the length of the longest palindromic subsequence in it. Solution: 1. public static void main(String[]...
The input is a string of digits. You must find the longest substring which first half digits sum is equal to the right half digits sum....
A Bitonic Subsequence is a part of a sequence that is formed first by increasing numbers, and after that by decreasing numbers. Write a...
Given an integer array, you have to find a contiguous subarray with the largest sum, and return that sum. Solution: 1. public static...