Featured Article

Count of distinct substrings of a string using Suffix Trie

Given a string of length n of lowercase alphabet characters, we need to count total number of distinct substrings of this string. Examples: Input : str = “ababa” Output : 10 Total number of distinct substring are 10, which are, “”, “a”, “b”, “ab”, “ba”, “aba”, “bab”, “abab”, “baba” and “ababa” The idea is create… Read More »

Continuous Tree

A tree is Continuous tree if in each root to leaf path, absolute difference between keys of two adjacent is 1. We are given a binary tree, we need to check if tree is continuous or not. Examples: Input : 3 / \ 2 4 / \ \ 1 3 5 Output: “Yes” // 3->2->1… Read More »

SQL | WHERE Clause

WHERE keyword is used for fetching filtered data in a result set. It is used to fetch data according to a particular criteria. WHERE keyword can also be used to filter data by matching patterns. Basic Syntax: SELECT column1,column2 FROM table_name WHERE column_name operator value; column1 , column2: fields int the table table_name: name of… Read More »

Compressing and Decompressing files in Java

DeflaterOutputStream and InflaterInputStream  classes are provided in Java to compress and decompress the file contents. These classes provide useful methods that can be used for compressing  the file content. Compressing a File using DeflaterOutputStream This class implements an output stream filter for compressing data in the “deflate” compression format. It is also used as the basis… Read More »

Find next Smaller of next Greater in an array

Given array of integer, find the next smaller of next greater element of every element in array. Note : Elements for which no greater element exists or no smaller of greater element exist, print -1. Examples: Input : arr[] = {5, 1, 9, 2, 5, 1, 7} Output: 2 2 -1 1 -1 -1 -1… Read More »

Group all occurrences of characters according to first appearance

Given a string of lowercase characters, the task is to print the string in a manner such that a character comes first in string displays first with all its occurrences in string. Examples: Input : str = “geeksforgeeks” Output: ggeeeekkssfor Explanation: In the given string ‘g’ comes first and occurs 2 times so it is… Read More »

Static methods vs Instance methods in Java

Instance Method Instance method are methods which require an object of its class to be created before it can be called. To invoke a instance method, we have to create an Object of the class in within which it defined. public void geek(String name) { // code to be executed…. } // Return type can… Read More »