Posts

Showing posts from July, 2017

Pattern problem in java.

Need to display right angle triangle format with decreasing term based on the input. Input 5 output:             1          2 2       3 3 3    4 4 4 4 5 5 5 5 5

One in Another in java

Here you are given with two inputs one is alpha numeric and other is just number in the form of string. Now you have to check the numeric value in first string is present in second string. If it is present you need to get the index of it. Input abc6efg 123678 Output: 3 Input: a1bc6ef 123678 Output: 1

Playing with Digits in Java

Here you are given with an Integer, you need to display the count of non-repeated integers starting from 1 to till that number. Input 7 Output: 7 as there are no repeated counts from 1 to 7. similarly Input : 100 Output: 10 (11,22,33,44,55,66,77,88,99,100 these are the repeated  digit counts from 1 to 100).

Find the Kth largest value in array using java

You are given with array and integer K, now you need to find the kth largest value in the array. Input 5     ----Array size 11  ----------------- 4                         | 3                         |Array elements 1                         | 2   ----------------- 3   ----K th Value. Output: 3 (Since it is looking 3rd largest value in the array) Input: 5 4 3 5 9 1 1 Output: 9 (Since it is looking for 1st largest value in the array)

Separator in String in java

You are given with a string along with delimiter such as ")" ,"(" , "}" ,"{" ,"[" , "]" should be replaced and saved as next element in array. Whereas delimiter is doubled "))" should be replaced with ")" of that respective delimiter. Input abc(e))df) Output: abc e)df Input: abc(efg)hij{lmn} Output: abc efg hij lmn

Reversing of words in java

You are given a phrase, you need to reverse the phrase. Input dog bites man Output man bites dog

Hangout With Anagram in java

You are given with a words of array, now you need list only anagrams as output array. Anagram is a direct word ,by rearranging letters of a words or phrase produces new word or phrase. Input: tea ate eat apple java vaja cut utc Output: tea ate eat java vaja cut utc

Alternate Sorting in java

Your are given with an array, now you need to show the output as -first maximum number followed by first minimum number followed by second maximum number and second minimum number and so on.... Input 7   ----Array size 1      ------------- 2                      | 3                      | 4                      |---Array elements 5                      | 6                      | 7      ------------ Output: 7 1 6 2 5 3 4

Largest Square House in java

You are given matrix 1's represent trees and 0's represent empty space, now you have to build a house in space such that it should form grid/square, then return the dimension of grid/square. Input 4 5 1 1 1 0 0 1 1 1 0 0 0 1 0 1 0 0 0 1 1 1 Output: 2$2. Input: 4 5 1 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 1 1 Output: 2$3. first value indicates row and after $ indicates column.

Toeplitz Matrix in java

Toeplitz matrix where all the diagonals are equal. Input: 4 5 6 7 8 9 2 4 6 7 8 9 1 4 6 7 8 0 1 4 6 7 Output:  1 Input: 3 3 1 2 3 4 5 6 7 8 9  Output: -1

Stepping Number

In this program we are given with an long integer, if difference of adjacent digit is 1, then it is a stepping number else return -1 Input: 123 Output: 1 Input: 890 Output: -1

Unity in Zeros

In this program you are given with an array with 0's as elements in between the non zero elements, now you have to sort the array in such way that non zero elements should not loose the sequence whereas zeros should be in the last. Alternative Method. Input: 5    ---Array size 1 2 0 3 0 Output: 1 2 3 0 0

One In Another

In this program you are given with two strings, you need to find character of string2 in string1, once it is find then get index of that character and return the same else returns zero. Input:  adf6ysh 123456 output: 3 Input:  adf6ysh 123455 output: 0

Printing a format in java

Print the format, you are given with an Integer, based on that integer print * sequential order as shown below Input: 5 Output: * ** *** **** *****

Divide and Rule: You are given with an array size and elements, need to remove any one of the elements, such that remaining elements has to divided into two halves and their sum should be equal, if both halves sum are equal need to return 1 else return -1.

Divide and Rule: You are given with an array size and elements, need to remove any one of the elements, such that remaining elements has to divided into two halves and their sum should be equal, if both halves sum are equal need to return 1 else return -1. Input: 7                         //Array size 1   ----------------- 2                         | 3                         | 4                         | -------Array Elements 5                         | 6                         | 7------------------- Output: -1

Convert decimal to binary number, then count the consecutive 1's in the binary number.

Convert decimal to binary number, then count the consecutive 1's in the binary number. Input: 63 Output: 6 Explanation: 63 decimal format binary format for 63 is 111111, so there are 6 consecutive 1's in the binary number. another example: If input is 13, binary format is 1101, so the output is 2. another example : input 439 output is 3. Since binary format is 110110111. 3 consecutive 1's are found to be highest in it. next example: input 65535 output is 16. since binary format is 1111111111111111. 16 consecutive 1's are found to be highest in it.

Learning about Key Value pair in Java

Input: 3 sam 99912222  tom 11122222 harry 12299933 sam edward  harry  Output: sam=99912222  Not found harry=12299933