# Category: Yahoo

## Majority Element- Boyer–Moore majority vote algorithm

Objec­tive:  Given an array of integer write an algorithm to find the majority element in it (if exist). Majority Element: If an element appears more than n/2 times in array where n is the size...

## Majority Element – Part 1

Objective:  Given an array of integer write an algorithm to find the majority element in it (if exist). Majority Element: If an element appears more than n/2 times in array where n is the size...

## Maximum Subarray OR Largest Sum Contiguous Subarray Problem – Divide and Conquer

Objec­tive:  The max­i­mum sub­ar­ray prob­lem is the task of find­ing the con­tigu­ous sub­ar­ray within a one-dimensional array of num­bers which has the largest sum. Exam­ple: int [] A = {−2, 1, −3, 4, −1, 2, 1, −5, 4}; Output:...

## Find two elements whose sum is closest to zero

Objective: Given an array of positive and negative integers, write a algorithm to find the two elements such their sum is closest to zero. Example: int a [] = {1, 4, -5, 3, -2,...

## Find the first repeating character in a given string

Objective: Given a string, write an algorithm to find the first repeating character in it. Example: String input = “horizon tutorials” Output: ‘o’ String input = “algorithms” Output: No repeating character found. Approach: Naive...

## Find longest Snake sequence in a given matrix

Objective: Given two dimensional matrix, write an algorithm to find out the snake sequence which has the maximum length. There could be many snake sequence in the matrix, you need to return the one...

## Dynamic Programming – Count all paths in 2D Matrix with Obstructions in it

Objective: Given two dimensional matrix, write an algorithm to count all possible paths from top left corner to bottom-right corner. You are allowed to move only in two directions, move right OR move down....

## Dynamic Programming – Count all paths from top left to bottom right of a mXn matrix

Objective: Given two dimensional matrix, write an algorithm to count all possible paths from top left corner to bottom-right corner. You are allowed to move only in two directions, move right OR move down....

## Print All Diagonals of a given matrix

Objective: Given two dimensional matrix, write an algorithm to print all the diagonals of matrix. Example: Approach: We will solve this problem in two parts. first half of diagonals and second half of diagonals....

## Dynamic Programming – Highway Billboard Problem

Objective:  Suppose you’re managing construction of billboards on the Rocky & Bullwinkle Memorial Highway, a heavily traveled stretch of road that runs west-east for M miles. The possible sites for billboards are given by...

## Kadane’s Algorithm – Maximum Subarray Problem

Objective:  The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum. Example: int [] A = {−2, 1, −3, 4, −1, 2, 1, −5,...

## Reverse a Linked List in groups of given size ‘K’

Objective: Given a linked list and integer ‘k’, write an algorithm to reverse the linked list in groups of size ‘k’. Example: Approach: Earlier we have seen how to reverse a linked list, solution...

## Dynamic Programming — Longest Palindromic Subsequence

Objective: Given a string, find a longest palindromic subsequence in it. What is Longest Palindromic Subsequence: A longest palindromic subsequence is a sequence that appears in the same relative order, but not necessarily contiguous(not...

## Dynamic Programming – Longest Common Subsequence

Objective: Given two string sequences, write an algorithm to find the length of longest subsequence present in both of them. These kind of dynamic programming questions are very famous in the interviews like Amazon,...

## Print All N Length Strings from Given Number K

Objective: Given Number K, Print all the strings of N length. Example: N = 2, K = 3 [1, 1] [2, 1] [3, 1] [1, 2] [2, 2] [3, 2] [1, 3] [2, 3]...