The shortlisting was done through our university based on our resume and academic performance. I was shortlisted and had two interviews of 45 minutes, each with a break of fifteen minutes in between. Both of them were technical rounds involving hands-on coding in a shared google doc while I was on a video call through Hangouts with the interviewer from Google.
Question: A boolean expression is given in the form of a string. It contains one variable x; logical operators – ‘and’, ‘or’ and relational operators – ‘>’, ‘<‘ (there is no >= or <=). Find if the expression always evaluates to False. If yes, output False, otherwise if there exists at least one x such that the given expression can be true, output true.
1. “x<0 and x>5”
Output – False
Explanation – This can never be true as there is no ‘x’ such as x<0 and x>5. So, the given boolean expression always evaluates to false.
2. “x>0 or x<-1”
Output – True
Explanation – We have at least one ‘x’ for which given boolean expression evaluates to true. For example, put x=2 in the given expression, and it evaluates to true.
Hint: Whenever there is only ‘or’ in the boolean expression, the result is always true. (Eg: x>0 or x<0 – There exists some x such that this is true and whatever be the latter part of the expression, it evaluates to true as only ‘or’ is present. If there is no ‘or’ present (only ‘and’ is there), then we check for the expressions – if you find at least two contradicting expressions as in example 1 (that is their solution sets are disjoint), then the output is False (as we have only ‘and’ logical operation which evaluates to False unless all the expressions are True), otherwise it is True.
I have no idea how to approach the problem when both ‘and, ‘ ‘or’ are present in the expression, and I could not find such a problem anywhere on the internet.
I request someone who read this article to contribute the code to this problem kindly. (preferably in C++)
Question: Given a string, find the minimum number of cuts to split the string so that all the resulting substrings are palindromes.
Explanation: Minimum number of cuts to partition “google” into palindromes = 2 that is –
goog|l|e – where ‘|’ refers to a cut, the three resulting palindromes are “goog”, “l”, “e”. Therefore, the minimum number of cuts required = 2.
Hint: Refer to this article.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. In case you are prepared, test your skills using TCS, Wipro, Amazon and Microsoft Test Serieses.