Tabulation vs Memoizatation

Prerequisite – Dynamic Programming, How to solve Dynamic Programming problems? There are following two different ways to store the values so that the values of a problem can be reused. Here, will discuss two patterns of solving DP problem: Tabulation: Bottom Up Memoization: Top Down Before getting to the definitions of the above two terms… Read More »

Minimum lines to cover all points

Given N points in 2-dimensional space, we need to print the count of the minimum number of lines which traverse through all these N points and which go through a specific (xO, yO) point also. Examples: If given points are (-1, 3), (4, 3), (2, 1), (-1, -2), (3, -3) and (xO, yO) point is… Read More »

Find the first repeated character in a string

Given a string, find the first repeated character in it. We need to find the character that occurs more than once and whose index of first occurrence is smallest. Examples: Input: ch = “geeksforgeeks” Output: e e is the first element that repeats Input: str = “hello geeks” Output: l l is the first element… Read More »

Daily life Linux Commands

Clear the Terminal : In our daily life, we use to work on Terminal if we are using LINUX. Continuous working on terminal make terminal screen full with commands and for removing them and making our screen totally free of character, we often use clear command. Key combination ‘Ctrl+l‘ has the same effect as ‘clear‘ command. So from… Read More »

How to solve a Dynamic Programming Problem ?

Dynamic Programming (DP) is a technique that solves some particular type of problems in Polynomial Time. Dynamic Programming solutions are faster than exponential brute method and can be easily proved for their correctness. Before we study how to think Dynamically for a problem, we need to learn: Overlapping Subproblems Optimal Substructure Property Steps to solve… Read More »

Java.util.Locale Class in Java | Set 2

Java.util.Locale Class in Java | Set 1 More methods: getDisplayVariant() : java.util.Locale.getDisplayVariant() displays variant of the Locale Syntax : public final String getDisplayVariant() Parameters : —- Return : ———– getDisplayVariant(Locale in) : java.util.Locale.Locale in(Locale in) returns the variant of “in” locale. Syntax : public final String getDisplayVariant(Locale in) Parameters : in : the instance local… Read More »

Java.util.Locale Class in Java | Set 1

As the name suggests util.Locale Class is used to perform locale task and provides locale information for the user. Declaration : public final class Locale extends Object implements Cloneable, Serializable Constructors : Locale(String L) : Creates Locale form the given language code. Locale(String L, String C) : Creates Locale form the given language, country code.… Read More »

Multiples of 3 and 5 without using % operator

Write a short program that prints each number from 1 to n on a new line. For each multiple of 3, print “Multiple of 3” instead of the number. For each multiple of 5, print “Multiple of 5” instead of the number. For numbers which are multiples of both 3 and 5, print “Multiple of… Read More »

Using else conditional statement with for loop in python

In most of the programming languages (C/C++, Java, etc), the use of else statement has been restricted with the if conditional statements. But Python also allows us to use the else condition with for loops. The else block just after for/while is executed only when the loop is NOT terminated by a break statement. Else… Read More »

Iterative program to count leaf nodes in a Binary Tree

Given a binary tree, count leaves in the tree without using recursion. A node is a leaf node if both left and right children of it are NULL. Example Tree Leaves count for the above tree is 3. Asked In: GATE-2007 The idea is to use level order traversal. During traversal, if we find a… Read More »