Dutch National Flag Problem

Dutch National Flag Problem Given an array with 0’s ,1’s ,2’s . Arrange them such that all 0’s , all 1’s and all 2’s are grouped together in a sorted manner. I/P: 0 1 0 1 2 0 1 2 0 1 1 O/p: 0 0 0 0 1 1 1 1 1 2 2… Read More »

Print all possible words from phone digits

Print all possible words from phone digits You are given a digit string. Print all combination that the number could represent. Example: Input : “23” Output ad ae af bd be bf cd ce cf

STRHH-Half of the Half -Spoj

Given a sequence of 2*k characters, please print every second character from the first half of the sequence. Start printing with the first character. Input: 4 your progress is noticeable Output: y po i ntc Approach Straight forward approach just find out the length of the string, And just keep printing till half of the… Read More »

Stack Implementation Using Array

Stack Implementation Using Array   Stack can be implemented using Array. Stack : Introduction C- Implementation of stack using Array. Performance Analysis Time Complexity Push() : O(1). Time Complexity POP() : O(1). Limitation Maximum Size of the Stack should be defined before using stack.

Stack : Introduction

Stack Stack is a basic data structure that can imagine as a stack or pile of playing cards. Stack is the structure in which basic operation Insertion (PUSH) and Deletion (POP) takes place form one end of the stack either from Top or Bottom. Stack follow the LIFO (Last IN First Out) i.e. last element… Read More »

How to Check Grammar is LL(1) or not.

How to Check Grammar is LL(1) or not LL(1) grammar is a Context free Grammar which can be parsed by LL(1) Parser. Parsing is the process of finding out whether the string belong to the given grammar after following the given grammar rules. In LL(1) Parser. First L stands for scanning input from Left to… Read More »

If one string is a permutation of other

Given two strings, we have to find out If one string is a permutation of other.   Example: “life” and “file” are permutation of each other   Approach If Two strings are permutation of each other they will have same characters, but characters are placed in different order. If length of two string are different… Read More »

Print Anti-Diagonal elements of Array

Given an N*N Array, You have to Print Anti-Diagonal elements of Array I/P 1 2 3 4 5 6 7 8 9 O/p 1 2 4 3 5 7 6 8 9 Here is python Implementation of Above problem Output: [1] [2,4] [3,5,7] [6,8] [9]

Adding 1 to a number-leetcode

Given a non-negative number represented as an array of digits, plus one to the number. Also, the numbers are stored such that the most significant digit is at the head of the list. Example: I/p: [2,1,3] O/p: [2,1,4] I/p: [9,9] O/p: [1,0,0] I/p: [0,2,1,2] O/p: [2,1,3] Approach You will be thinking that problem is so… Read More »

Maximum Sum Contiguous Sub Array

Given an array containing both positive and negative integers. Find out the Maximum Sum Contiguous Sub Array. For example: Let say Array: [ -3 2 1 -4 2 ] Maximum sub array contiguous sum = 3. Approach: We will take two variable one variable will maintain the current_sum, and second will maintain max_so. Initially c_sum=… Read More »