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
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
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
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
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
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
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
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
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
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
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:
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.
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
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
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
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
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
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.
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
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.
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
(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
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
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
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
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
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
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
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
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
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
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
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
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:
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
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
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:
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]
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.
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
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
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
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)
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]
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]
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
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
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).
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
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
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.
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:
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
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 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
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
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
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
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
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
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
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,
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
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
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
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
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
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
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
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 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 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, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of