## LeetCode – Sort Characters By Frequency

Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: “tree” Output: “eert” Explanation: ‘e’ appears twice while ‘r’ and ‘t’ both appear

## LeetCode – Count Square Submatrices with All Ones

Given a m * n matrix of ones and zeros, return how many square submatrices have all ones. Example 1: Input: matrix = [   [0,1,1,1],   [1,1,1,1],   [0,1,1,1]

## LeetCode – Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Example 1: Input: root = [3,1,4,null,2], k = 1 3 / \ 1

## LeetCode – Online Stock Span

Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock’s price for the current day. The span of the stock’s price today is

## LeetCode – Permutation in String

Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the

## LeetCode – Find All Anagrams in a String

Given a string s and a non-empty string p, find all the start indices of p‘s anagrams in s. Strings consists of lowercase English letters only and the length of

## LeetCode – Odd Even Linked List

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in

## LeetCode – Maximum Sum Circular Subarray

Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning

## LeetCode – Implement Trie (Prefix Tree)

Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie.insert(“apple”); trie.search(“apple”); // returns true trie.search(“app”); // returns false trie.startsWith(“app”); // returns true trie.insert(“app”); trie.search(“app”);

## LeetCode – Remove K Digits

Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of num is

## LeetCode – Single Element in a Sorted Array

You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only

## LeetCode – Flood Fill

An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, sc) representing the

## LeetCode – Find the Town Judge

In a town, there are N people labelled from 1 to N.  There is a rumor that one of these people is secretly the town judge. If the town judge exists, then:

## LeetCode – Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt.

## LeetCode – Check If It Is a Straight Line

You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane. Example

## LeetCode – Cousins in Binary Tree

In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins

## LeetCode – Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array

## LeetCode – First Unique Character in a String

Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = “leetcode” return 0. s = “loveleetcode”, return

## LeetCode – Number Complement

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Example 1: Input: 5 Output: 2 Explanation: The binary representation

## LeetCode – Ransom Note

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from

## LeetCode – Jewels and Stones

You’re given strings J representing the types of stones that are jewels, and S representing the stones you have.  Each character in S is a type of stone you have.

## LeetCode – First Bad Version

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is

## LeetCode – Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree – 30Days Challenge

Given a binary tree where each path going from the root to any leaf form a valid sequence, check if a given string is a valid sequence in such binary tree.

## LeetCode – Binary Tree Maximum Path Sum – 30Days Challenge

Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in

## LeetCode – Maximal Square – 30Days Challenge

Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. Example: Input: 1 0 1 0 0 1 0

## LeetCode – Leftmost Column with at Least a One – 30Days Challenge

(This problem is an interactive problem.) A binary matrix means that all elements are 0 or 1. For each individual row of the matrix, this row is sorted in non-decreasing order. Given a row-sorted binary matrix

## LeetCode – Construct Binary Search Tree from Preorder Traversal – 30Days Challenge

Return the root node of a binary search tree that matches the given preorder traversal. (Recall that a binary search tree is a binary tree where for every node, any descendant

## LeetCode – Search in Rotated Sorted Array – 30Days Challenge

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If

## LeetCode – Valid Parenthesis String – 30Days Challenge

Given a string containing only three types of characters: ‘(‘, ‘)’ and ‘*’, write a function to check whether this string is valid. We define the validity of a string

## LeetCode – Contiguous Array – 30Days Challenge

Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0, 1] is the

## LeetCode – Last Stone Weight – 30Days Challenge

We have a collection of stones, each stone has a positive integer weight. Each turn, we choose the two heaviest stones and smash them together.  Suppose the stones have weights x and y

## LeetCode – Bitwise AND of Numbers Range – 30Days Challenge

Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. Example 1: Input: [5,7] Output: 4

## LeetCode – First Unique Number – 30Days Challenge

You have a queue of integers, you need to retrieve the first unique integer in the queue. Implement the FirstUnique class: FirstUnique(int[] nums) Initializes the object with the numbers in the

## LeetCode – Backspace String Compare – 30Days Challenge

Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. Note that after backspacing an empty text, the text will continue

## LeetCode – Perform String Shifts – 30Days Challenge

You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [direction, amount]: direction can be 0 (for left shift) or 1 (for right shift).  amount is the amount by which

## LeetCode – Happy Number – 30Days Challenge

Write an algorithm to determine if a number n is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number

## LeetCode – Best Time to Buy and Sell Stock II – 30Days Challenge

Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You

## LeetCode – Product of Array Except Self – 30Days Challenge

Given an array nums of n integers where n > 1,  return an array output such that output[i] is equal to the product of all the elements of nums except

## LeetCode – Longest Common Subsequence – 30Days Challenge

Given two strings text1 and text2, return the length of their longest common subsequence. A subsequence of a string is a new string generated from the original string with some

## LeetCode – Minimum Path Sum – 30Days Challenge

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note:

## LeetCode – Diameter of Binary Tree – 30Days Challenge

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between

## LeetCode – Min Stack – 30Days Challenge

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. 1. push(x) — Push element x onto stack. 2. pop() — Removes the element

## LeetCode – Middle of the Linked List – 30Days Challenge

Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. Example 1: Input: [1,2,3,4,5] Output:

## LeetCode – Counting Elements – 30Days Challenge

Given an integer array arr, count element x such that x + 1 is also in arr. If there’re duplicates in arr, count them seperately.   Example 1: Input: arr = [1,2,3]

## LeetCode – Jump Game – 30Days Challenge

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position.

## LeetCode – Number of Islands – 30Days Challenge

Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally

## LeetCode – Subarray Sum Equals K – 30Days Challenge

Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k

## LeetCode – Group Anagrams – 30Days Challenge

Given an array of strings, group anagrams together. Example: Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Output: [ [“ate”,”eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note: All inputs will be in lowercase. The

## LeetCode – LRU Cache – 30Days Challenge

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) – Get the value (will always be positive)

## LeetCode – Move Zeroes – 30Days Challenge

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0]

## LeetCode – Maximum Subarray – 30Days Challenge

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1]

## LeetCode – Single Number – 30Days Challenge

Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it

## Convert a Binary Tree into its Mirror Tree

Given a binary tree, invert the binary tree and return it. Look at the example for more details. Mirror of a Tree: Mirror of a Binary Tree T is another

## ZigZag Level Order Traversal BT

Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).

## LeetCode – Circular Permutation in Binary Representation (Java)

Given 2 integers n and start. Your task is return any permutation p of (0,1,2…..,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit

## Stateless Widget in Flutter

Before beginning development with Flutter, one should familiar with Widgets like Stateless and Stateful. Today we will talk on Stateless Widget. Stateless Widget As the name suggests, Stateless widgets are immutable. Stateless widgets remain

## Stateful Widget in Flutter

When building Flutter apps, most of the time we are dealing with widgets. Widgets are everywhere in Flutter. Flutter uses widgets to describe reusable building blocks in the user interface.

## LeetCode – Reverse Words in a String

Given an input string, reverse the string word by word. Example 1: Input: “the sky is blue” Output: “blue is sky the” Example 2: Input: ” hello world! ” Output:

## Find pair with given difference K in the array

Given an array A of integers and another non-negative integer K, find if there exist 2 indices i and j such that A[i] – A[j] = K, i != j.

## Find Path with Maximum Gold

In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is

## Largest Continuous Sub Array with Zero Sum – Java

Find the largest continuous sequence in an array which sums to zero. Example: Input: { 1 , 3 , -1 , 2 , -4 , 1} Output: {3 , -1

## Colorful Number

For Given Number N find if its COLORFUL number or not Number is COLORFUL number if product of every digit of a contiguous subsequence is different. A number can be

## LeetCode – Minimum Absolute Difference

Given an array of distinct integers arr[], find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect

## Given an Array of Integers and Target Number, Find Pair having Sum as Target

Given an array of integers A[], find two numbers such that they add up to a specific target number B. The program should return indices of the two numbers such

## Group all anagrams from a given array of Strings

Given an array of strings, return all groups of strings that are anagrams. Represent a group by a list of integers representing the index in the original list. Look at

## Understand SOAP Message Structure

Overview In the previous articles, We have gone through basics of SOAP Webservice and Steps to create SOAP Webservice. As we are knowing that SOAP forms message before communicating with

## Test SOAP Web Service using Eclipse

Overview In a previous article, we have created SOAP Web service with JAX-WS API. Also, we have covered different ways to consume or test SOAP Web Service. Today we will

## Consume SOAP Web Service with wsimport

Overview In a previous article, we have created SOAP Web service with JAX-WS API. Next part is how can we consume it in Java, How to create stub files or

## SOAP Web Service with JAX-WS API

Overview In the previous article we have gone through an overview of SOAP web service and advantage and disadvantage of it. In today’s article, we will create SOAP web service

## SOAP Web Services

Overview As per W3C, web service can be defined as, a software system designed to support interoperable machine-to-machine interaction over a network. Web services are: 1. Platform independent 2. Designed

## Java Memory Profiling with VisualVM

Overview In the previous article, we navigate through jmap tool to analyze application performance, jmap is a console based which did not have a visual interface to analyze the data,

## WebSocket Client API in Java 9 with Example

Overview WebSocket API is another addition to the java.httpclient package in Java 9. As explained earlier, it enables having full duplex communication between the client and the server. This package

## HTTP/2 Client in Java 9

Overview In Java 9, Oracle has released a new version of HTTP client API which will support HTTP/2 protocol and WebSocket features. As existing HTTP Client API has numerous issues

## Module Directives in Java 9

Overview We have discussed Java 9 Modularity and Module System. Also we have discussed How to create first Module in Java 9 using eclipse. Here we will discuss in detail

## Mediator Design Pattern in Java

Overview Mediator design pattern is a behavioral design pattern. It is used to provide a centralized communication medium between different objects in a system. The Gang of Four has indicated

## Observer Design Pattern in Java

Overview Observer Pattern is a behavioral type design pattern. According to GoF, the observer design pattern is; The observer pattern defines a one-to-many dependency between objects so that when one

## Difference between ArrayList and LinkedList

1. Memory Allocation ArrayList uses Array as underline datastructure to store the elements, and we know Array stores elements in consecutive manner. In LinkedList, elements can be stored at any

## Chain of Responsibility Design Pattern in Java

Overview Chain of Responsibility Pattern can be used when we want to give more than one object a chance to handle a request. The pattern can be used to achieve

## JShell with Example – Java 9

Java 9 introduces JShell and a Read-Eval-Print Loop (REPL) for the Java Programming Language. REPL allows us to evaluate code snippets such as declarations, statements, expressions. We can test our

## Can You Crack The Code : Riddle Mystery 2

Can You Crack The Code Riddle Mystery 2 In this article “Can You Crack The Code Riddle Mystery 2”, you will find very interesting Riddle Mystery. A Number Lock has

## Can You Crack The Code : Riddle Mystery 1

Can You Crack The Code Riddle Mystery 1 In this article “Can You Crack The Code Riddle Mystery 1”, you will find very interesting Riddle Mystery. A Number Lock has

## Bubble Sort Algorithm

Bubble Sort Algorithm Bubble sort algorithm, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of