LeetCode Maximum Erasure Value

You are given an array of positive integers nums and want to erase a subarray containing unique elements. The score you get by erasing the subarray is equal to the sum of its elements. Return the maximum score you can get by erasing exactly one subarray. An array b is called to be a subarray of a if it forms a contiguous subsequence of a, that is, if it is equal to a[l],a[l+1],…,a[r] for some (l,r). Example…… Continue reading LeetCode Maximum Erasure Value

Jump Search Algorithm In Java

Jump search algorithm is a pretty new algorithm to search for an element in a sorted array. The idea of jump search is to skip the number of comparisons by jumping the indices by length m while performing the searching thus getting a better time complexity than linear search. For jump search m is determined…… Continue reading Jump Search Algorithm In Java

Knuth Morris Pratt Pattern Search Algorithm

What is Knuth Morris Pratt or KMP algorithm ? KMP is an algorithm which is used in the applications of pattern matching like, find a Word ‘W’ in a String ‘S’ in O(M+N) time complexity M being the length of the string and N being the length of the word. Here is the video explanation…… Continue reading Knuth Morris Pratt Pattern Search Algorithm

Binary Search Algorithm In Java

Binary Search is a Logarithmic search which finds the target element in a sorted array in O(logN) times compared to linear search which takes O(N). Binary search uses divide and conquer approach and can only work on a sorted array or list. In this approach, we divide the input collections into two equal halves using…… Continue reading Binary Search Algorithm In Java

Leetcode Integer to Roman Java Solution

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one’s added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II. Roman numerals are…… Continue reading Leetcode Integer to Roman Java Solution

Leetcode Container With Most Water Java Solution

Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container and n is at least 2. The…… Continue reading Leetcode Container With Most Water Java Solution

Leetcode Binary Tree Level Order Traversal II Java Solution

Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] Solution:We can solve it multiple ways…… Continue reading Leetcode Binary Tree Level Order Traversal II Java Solution

Leetcode Unique Paths Java Solution

A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below). How many possible unique paths are there?…… Continue reading Leetcode Unique Paths Java Solution

Leetcode Reconstruct Itinerary Java Solution

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK. Note: If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order…… Continue reading Leetcode Reconstruct Itinerary Java Solution