Skiing on Mountains Matrix : “John Snow” likes Skiing on Mountains a lot.That’s not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most point one has to wait for ski-lift to get to higher altitude.

“John Snow” seeks your help to know the longest run possible with the given peaks, As (“John Snow knows nothing” ), That altitude of different peaks is given by a grid of numbers. Look at this example Skiing on Mountains Matrix Path: [Read more…]

## The greedy coins game Dynamic Programming

The greedy coins game Dynamic Programming Solution :

Question statement There is a row of 2n coins on the table; each coin can have any positive integer value. Two players alternate turns.

On a player’s turn he/she must take one of the two coins on either END of the row of remaining coins, so with each turn the row gets shorter by one.

After all the coins have been taken, the player with the higher total value is the winner.

Decide Strategy and Determine the maximum possible amount of money we can definitely win if we move first. [Read more…]

## Handle duplicates in Binary Search Tree

In a Binary Search Tree (BST), all keys in left subtree of a key must be smaller and all keys in right subtree must be greater. So a Binary Search Tree by definition has distinct keys and duplicates in binary search tree are not allowed.

How to allow duplicates where every insertion inserts one more key with a value and every deletion deletes one occurrence?

A **Simple Solution** is to allow same keys with count. For example consider insertion of keys 3, 6, 7, 8, 8, 8, 10, 12, 12 in an empty Binary Search Tree [Read more…]

## Minimum insertions to form a palindrome

Given a string, find the minimum number of characters to be inserted to form Palindrome string out of given string

Before we go further, let us understand with few examples:

ab: Number of insertions required is 1. **b**ab

aa: Number of insertions required is 0. aa

[Read more…]

## Binary Tree Isomorphic to each other

Find weather two given trees are isomorphic to each other or not.

Lets understand What is isomorphic strings

AAB and XXY are IsoMorphic to each other, consider A replaces/morphs as X and B as Y, then both strings are isomorphic.

ABC and XXY are not IsoMorphic.

[Read more…]

## Maximum occurred Smallest integer in n ranges

### Maximum occurred integer in n ranges

Given n ranges in the form of Start Number and End Number in Two Array L and R such that

L[i]-R[i] is one range given. Our task is to find the maximum occurred smallest (first) integer in all the ranges. Means If more than one integer occurs max times, print the smallest one.

In other you can find similar code in

**Time Complexity**: O(n + MAX) and **Space Complexity : **O(Max)

We have tried to reduce complexity to O(n+m), space complexity : O(m) where m is largest integer in L or R

means m is largest range number.

## Best Java Book | Top Java Programming Book for Beginners

Being certified Java programmer SE 7, Enterprise Edition ( EE ) Application, etc. from Oracle & ex-Developer at Oracle, I can refer some of the * best java books* for learning.

Why Java? Java is most used language across many Multi National Companies like Amazon, Walmart, Goldman Sachs, Google, etc. for their coding because of its many features. Java is best for great architecture as it is easy to scale, multi-threading support, secure, robust and most important:** Java is easy to learn. **

It also provides the foundation for many languages and platforms such as Android, Groovy. So It becomes the most important language to learn.

Without wasting much of your time, let’s go through some of the *best programming books for Java* and grab the one which suits you.

Publisher | Title of Java Book | Pages in the book | Year | Price Range |
---|---|---|---|---|

O'Reilly Media | Head First Java, 2nd Edition | 688 | 2005 | Check Price |

Amazon Digital Services | JAVA: A Beginner to Expert Guide to Learning the Basics of Java Programming | 162 | 2016 | Check Price |

McGraw-Hill Education | Java: The Complete Reference, Ninth Edition | 1312 | 2014 | Check Price |

Prentice Hall | Thinking in Java (4th Edition) | 1150 | 2006 | Check Price |

Pearson | Java: An Introduction to Problem Solving and Programming (7th Edition) | 1024 | 2014 | Check Price |

CreateSpace Independent Publishing Platform | Data Structures and Algorithms Made Easy in Java: Data Structure and Algorithmic Puzzles, Second Edition | 450 | 2011 | Check Price |

Pearson | Building Java Programs: A Back to Basics Approach (4th Edition) | 1224 | 2016 | Check Price |

Addison-Wesley | Effective Java (2nd Edition) | 346 | 2008 | Check Price |

Pearson | Starting Out with Java: From Control Structures through Objects (6th Edition) | 1224 | 2015 | Check Price |

Pearson | Java How To Program (Early Objects) (10th Edition) | 1248 | 2014 | Check Price |

Prentice Hall | Core Java Volume I--Fundamentals (9th Edition) (Core Series) | 1008 | 2012 | Check Price |

Addison-Wesley Professional | Java Concurrency in Practice | 384 | 2006 | Check Price |

Some Other Recommendation for You

Here is the list of best Java Books which explains all stages of Java learning with their pros and cons.

[Read more…]

## Right view of Binary tree

We are given a Binary Tree, Print the Right view of Binary tree,

Right view of binary tree is : List of all nodes which are visible If you look at Binary tree from right side.

For example,

Right view of following tree is a, c, g, h a / \ b c / \ / \ d e f g \ h

Hint for logic : [Read more…]

## Find Nearest Minimum number in left side in O(n)

Given an array of integers, find the nearest smaller number for every element such that the smaller element is on left side.

Examples:

Input: arr[] = {1, 6, 4, 10, 2, 5} Output: {-1, 1, 1, 4, 1, 2} First element ('1') has no element on left side. For 6, there is only one smaller element on left side '1'. For 10, there are three smaller elements on left side (1, 6 and 4), nearest among the three elements is 4. Input: arr[] = {1, 3, 0, 2, 5} Output: {-1,1,-1, 0, 2}

## Find position of the only set bit

## Given a number having only one ‘1’ and all other ’0’s in its binary representation, find position of the only set bit.

Last Asked at @Microsoft

Say number is : 5 so its binary is 0101 , so this number is not having only 1 and other 0

Lets Say number is 16 , so it binary is , 10000 [Read more…]

- 1
- 2
- 3
- …
- 9
- Next Page »