This question was asked in an interview that I found interesting.
Here you go.
I know, There are other ways to do it better.
Map<Character, Character> exprssionMap = new HashMap<>();
exprssionMap.put('{', '}');
exprssionMap.put('[', ']');
exprssionMap.put('(', ')');
String inputExpression = "{[({{)}}]}";
int expressionLengh = inputExpression.length();
if (expressionLengh % 2 == 1) {
System.out.println("malformed Expression; Size of the Expression is not even number");
} else {
for (int i = 0; i < expressionLengh / 2; i++) {
if (!exprssionMap.get(inputExpression.charAt(i))
.equals(inputExpression.charAt(expressionLengh - 1 - i))) {
System.out.println(
"Matching expression not found for: " + inputExpression.charAt(i) + "; index:" + i);
}
}
}
Happy Coding.
Showing posts with label Logical. Show all posts
Showing posts with label Logical. Show all posts
Wednesday, 25 April 2018
Monday, 18 April 2016
Selenium Question
-
Assume, given web application is accessible in
one Machine ( IP : 10.10.10.10)
-
You need to write selenium tests and run.
-
You are not allowed to install / download any software
except browser in IP: 10.10.10.10.
How you do you
achieve this?
Analysis:
-
We can start coding in our local laptop , later
we can think about executing tests.
-
To find out locators ( xpaths / css / etc) ,
connect to the machine IP 10.10.10.10 via remote desktop and fetch as much info
as needed.
Now Execution part,
-
When we execute our test in local, tests should
run in the IP 10.10.10.10.
-
This can be achieved via selenium GRID.
-
Create a node in IP 10.10.10.10 and connect to a
HUB ( either in your laptop / IP 10.10.10.10)
-
Write Remote web driver code instead of plain
webdriver.
Just hit run. That’s all.
Friday, 15 April 2016
Logical Qn : Assume that you have 25 horses, and you want to pick the fastest 3 horses out of those 25. In each race, only 5 horses can run at the same time because there are only 5 tracks. What is the minimum number of races required to find the 3 fastest horses without using a stopwatch?
After analyzing a bit, Here are the pointers.
- We need to put all the horses into a race ( 5 at a time ) to find out the best 3 performers.
- Maximum 5 Horses in a race, so 5 times we need to conduct.
- After 5 Races, below is the table we can draw "ORDER by best performer"
Race1H1 - Race2H6 - Race3H11 - Race4H16 - Race5H21
Race1H2 - Race2H7 - Race3H12 - Race4H17 - Race5H22
Race1H3 - Race2H8 - Race3H13 - Race4H18 - Race5H23
Race1H4 - Race2H9 - Race3H14 - Race4H19 - Race5H24
Race1H5 - Race2H10 -Race3H15 - Race4H20 - Race5H25
Our Aim is to find the best three performers. so, we can eliminate last two rows.
Reason: We are least bothered about 4th and 5th best in each race.
They can not be one among top three performers.
Our Target table is
Race1H1 - Race2H6 - Race3H11 - Race4H16 - Race5H21
Race1H2 - Race2H7 - Race3H12 - Race4H17 - Race5H22
Race1H3 - Race2H8 - Race3H13 - Race4H18 - Race5H23
Now Race # 6: all top players in each race:
i.e
Race1H1 - Race2H6 - Race3H11 - Race4H16 - Race5H21
Assume results are, 1st place Race1H1 ; 2nd place Race2H6 ; 3rd place Race3H11
Now Race # 7: will gives the 2nd and 3rd place horse.
i.e we need to conduct a race with below set.
- Race2H6 - Race3H11
Race1H2 - Race2H7
Race1H3
why we eliminated other horses?
Elimination Set # 1
Race4H16 - Race5H21
Race4H17 - Race5H22
Race4H18 - Race5H23
Reason: As 3rd best horse is Race3H11. so, above set is definitely is not in 1,2,3 positions.
Elimination Set # 2
Race3H12
Race3H13
Reason: same as above.
Elimination Set # 3
Race2H8
Reason: as Race1H1 is 1st , there may be chance for 2nd is Race1H2 or Race2H6
chance for 3rd is Race1H3, Race2H6, Race2H7, Race3H11
but not Race2H8
so, Answer is 7
-
Subscribe to:
Comments (Atom)