Round 1
Question 1: You are given a string : sfdgjdg3e67jgjyg456
Fetch all numbers & provide their sum. Write the code such that if there is any slight change of requirements then there should be minimum code change for that.
Question 2 : Remove duplicates from the array of elements.
Question 3 : Add the given 2 numbers & these numbers are so large that can't be represented by any numeric type.
Fetch all numbers & provide their sum. Write the code such that if there is any slight change of requirements then there should be minimum code change for that.
Question 2 : Remove duplicates from the array of elements.
Question 3 : Add the given 2 numbers & these numbers are so large that can't be represented by any numeric type.
Round 2
Question 1 : How to efficiently find the given alphanumeric value in the array of millions of such numbers & if not present then
add it in the array.
Question 2 : Z -> 1...9
Find Z such that ZZ+ZZ+Z+Z+Z = 100
Question 3 : A, B , C-> 1...9
Find A & B such that AB*AB = CAB
Question 4 : Design the chess board
add it in the array.
Question 2 : Z -> 1...9
Find Z such that ZZ+ZZ+Z+Z+Z = 100
Question 3 : A, B , C-> 1...9
Find A & B such that AB*AB = CAB
Question 4 : Design the chess board
Then I was told by their recruiter that both the rounds are cleared & they don't have panel for next round, so I need to come again after 2-3 days. But I didnt get any response for 1 week, & when I enquired for that multiple times then I got the response that my profile is not shortlisted for further discussions. Strange...
Fast forward to 2022, I had one more discussion & had first coding round in which I was asked-
Implement the custom stack to get the most occurring number & if there is tie then get the number occurred last.
Though I was not able to provide the optimal approach but with the help of interviewer I was able to give almost working code.
And the below approach was due to the help of interviewer as I was not able to think about it.
So below, I have given my way of implementation of that approach. So at least this time experience was good as interviewer
behaved well & it was not like previous experiences with ServiceNow interviews.
Please comment & suggest the better approach or implementation-
Implement the custom stack to get the most occurring number & if there is tie then get the number occurred last.
Though I was not able to provide the optimal approach but with the help of interviewer I was able to give almost working code.
And the below approach was due to the help of interviewer as I was not able to think about it.
So below, I have given my way of implementation of that approach. So at least this time experience was good as interviewer
behaved well & it was not like previous experiences with ServiceNow interviews.
Please comment & suggest the better approach or implementation-
Well, I got one comment stating that I am not handing the exception when stack is empty, though I don't know what to do by handling the exception, if it happens. So one can also get the same comment during interview & believe many interviewers will be having the mindset of using either some try/catch or throw some other exception if stack is empty.
But my say is, if you are using jdk1.8+, which you will be, then why don't you use Optional here & let the client decide about the exception on his/her side.
So can have the above pop() function as shown below-
But my say is, if you are using jdk1.8+, which you will be, then why don't you use Optional here & let the client decide about the exception on his/her side.
So can have the above pop() function as shown below-