Category: Arrays

0

Print Stack in reverse order.

Objective: Given a stack, write a program to print the stack elements in reverse order. Example: Approach: Use Temporary stack: Take temporary stack, and copy all the items from the given stack to a...

0

Sort a given stack – Using Recursion

Objective: Given a stack of integers, write an algorithm to sort the stack using recursion.  Example: Original Stack: [14, 9, 67, 91, 101, 25] Sorted Stack: [9, 14, 25, 67, 91, 101] Original Stack:...

0

Given an array, Print sum of all subsets

Objective: Given an array of numbers, write an algorithm to print all the subsets sum individually.   Example: Given Input: [1, 2] Output: 3 1 2 0 Explanation: subsets are [0], [1], [2], [1, 2]...

0

Print all subsets of an array with a sum equal to zero

Objective: Given an array of integers write an algorithm to find all the subsets for which sum is equal to zero. The array contains both positive and negative integers. Example: Given Array: [8, 3,...

0

ZigZag OR Diagonal traversal in 2d array/Matrix using queue

Objective: Given a two-dimensional array or matrix, Write an algorithm to print the given matrix in a zigzag manner or in other words print all the diagonals of the matrix. Example: int [][] grid...

0

Number of Islands

Objective: 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 or vertically. Assume...

0

Evaluation of Postfix Expressions (Polish Postfix notation) | Set 2

Earlier we had discussed how to evaluate postfix expressions where operands are of single-digit. In this article, we will discuss how to evaluate postfix expressions for any number ( not necessarily single digit.) Postfix...

0

Reverse a Stack using recursion – In Place (Without using extra memory)

Objective: Given a Stack, write an algorithm to reverse the stack. Example: Original Stack: [14, 9, 67, 91, 101, 25] Reversed Stack: [25, 101, 91, 67, 9, 14] Approach: Use Recursion In this solution,...

0

Sort a given stack – Using Temporary Stack

Objective: Given a stack of integers, write an algorithm to sort the stack using a temporary stack.  Example: Given Stack: [14, 9, 67, 91, 101, 25] Sorted Stack: [9, 14, 25, 67, 91, 101]...

0

Grouping of Anagrams

Objective: Given an array of strings, write an algorithm to group the anagrams. Example: Input: [rat, art, cat, act, dog, god, tar, pat] Output: [rat, art, tar] [cat, act] [pat] [dog, god] Approach:  If...

%d bloggers like this: