January 22, 2019

Fidelity Problem 4: More commonly it is known as the Longest String Chain Problem.

Description: You are provided a dictionary of words in a form of a list of size n.You have to find Longest String Chain Length as per following explanation:
From the dictionary, you pick up a word and in each step, you remove a single letter from it and check whether the remaining word is still in the dictionary. If the remaining word is present in the dictionary you increase the chain length by one. You perform the same operations until you are left with the last remaining word present in the dictionary.
Mind it, you have to remove every possible character in the string and check the remaining word for chain length.
Input :
a
b
ba
bca
bda
bdca
Output: 4
Fidelity Question3: You are given an array of random positive and negative numbers.
You need to find the largest difference among all differences between two numbers in such a way that: 0<=i<n ; i<=j<n; ar[j]>ar[i] and the difference is ar[j]-ar[i].

For example: in array {2,3,1,5,4,7,9}

For 3 :{1} , max of set :1
For 1 :{} , empty as 1 is not bigger than any element in left
For 5 :{3,2,4} , max of set=4
For 4 :{2,1,3} , max of set=3
For 7 :{5,4,6,2,3} , max of set=6
For 9 :{7,6,8,4,5,2}, max of set=8

So the answer is the max of all above results{1,4,3,6,8} i.e 8.

If if you cannot get the required result return -1;

PS: (The question description is made easier than the original one)

Implementation:


Output:
7
2
3
4
1
5
7
9

The resultant maximum difference is 8
Fidelity Question2: 
You are given an array which you need to sort.
But Sorting here means different.Here by sorting we mean that if an array for example has following values:{3,4,2,9}, the resultant can be :

{4,2,3,9} OR {2,4,3,9} OR {4,2,9,3} OR {2,4,9,3}.

There are in total four different valid sorting resultants.

You need to find out the minimum number of moves to make an array sorted.

PS: (The question description is made easier than the original one)

Explanation: The question, in fact, needs that you move all the even elements on the left side of the array and all the odd elements on the right side but with the minimum number of moves.

Implementation:
Fidelity Questions: 

Problem 1:
Simple Question based on Inheritance and methods related to java.lang.Math class.

Description:
You have to implement 2 classes named Point2D and Point3D.
The purpose of the two classes is to find out the distance between two 2D points and two 3D points respectively.
The Structure of the classes should be as follows:

Point2D:

-- Two instance level properties x and y which depicts the x and y coordinate of a point in two-dimensional space.
--A parameterized constructor which takes two parameters and initializes its instance variables with it.
--A method double distanceFrom(Point2D p) which returns the distance between two points in 2-Dimensional space.
--A method void printDistance(double d) which outputs the distance in a single digit format of the largest number than it if the distance is not an integer literal.


Point3D:

--The class extends Point2D
-- Three instance level properties x, y, and z which depicts the x, y and z coordinate of a point in three-dimensional space.
--A parameterized constructor which takes three parameters and initializes its instance variables with it.
--A method double distanceFrom(Point3D p) which returns the distance between two points in 3-Dimensional space.
--A method void printDistance(double d) which outputs the distance in a single digit format of the largest number than it if the distance is not an integer literal.

Implementation:

Recursion In Maze Game

Question: Print all possible path in the 2D array from source to destination. Allowed motion is Horizontal right and vertical down.