kandi X-RAY | Interview Summary
kandi X-RAY | Interview Summary
Famous enterprise interview questions
Top functions reviewed by kandi - BETA
- Command - line test
- Add an element to the queue
- Check whether the queue contains the given element
- Removes the element from the queue
- Test program
- Return true if n is 1
- Check if the given sum is p1
- Calculate p1 for p1
- Converts a queue into an array
- Gets array as array
- Adds an element to the queue
- Adds the specified collection to the queue
- Removes all items from the queue
- Retrieves an element from the queue
- Checks if the queue is empty
- Removes the given Collection
- Checks if a collection contains all of the elements in the queue
- Returns the first item in the queue
- Retrieves and removes an element from the queue
- Main entry point
- Retain from the head of the set
- Returns the number of elements in the queue
- Returns an iterator over the items in this queue
- Main main loop
- Main method for testing
- Takes in the fist game in the forest
Interview Key Features
Interview Examples and Code Snippets
Trending Discussions on Interview
A few days ago in an interview, i was asked to explain following cases:...
ANSWERAnswered 2021-Jun-15 at 12:54
You must make a distinction between the static type of a variable (the type known at compile time) and the run time type of an object reference assigned to a variable.
The static type of
Parent in both cases because it is declared as
Parent p. No matter what you assign it. You may even assign it
The run time type of the value of
p after the assignment is
Child in the first case and
Parent in the second case. It would be undetermined if
It is okay to assign a
Child to a
Parent, because the
Child class derives from
Child is therefore a
Parent (in OO terms).
Parent is not a
Child, because it does not derive from it. Therefore, in the second case, you cannot cast
Child. In the first case the cast is valid, because you cast the object to its actual run time type. It tells the compiler, I know that this object assigned to a
Parent variable is a
Child, so, please, treat it as a
Child. This does not involve any conversion; however, a runtime check will be performed, possibly throwing an exception, if the cast was not allowed.
You were asked to explain it from point of view of stack and heap memory. I'm sorry to say, but this has absolutely nothing to do with stack or heap memory. It has to do with inheritance rules and assignment compatibility.
Of course, here we are dealing with reference types (classes). This allows us to derive
Parent. This would not be possible with value types (structs). The point is reference type versus value type, not heap versus stack, which is an implementation detail. And btw., a value type (struct) field in a class will also be stored on the heap.
You did not ask for it but casting to a derived type is mostly preceded by a type test, because you usually do not know the run time type in advance. Let us say that the
Child class adds a new method
DriveParentsToDespair() (only children can do this). Then you could use Type testing with pattern matching to test the type and assign it to a new variable at the same time:
I'm trying to sort my rows according to the Status (B), according to a custom order. I used to have Status in A, and the code worked fine, but then wanted to add an additional column before it and everything's been scuppered. Now getting a 1004 error.
My table spans A:L. Here's the code:...
ANSWERAnswered 2021-Jun-11 at 21:02
The error implies that it can't find a range to work with.
As we are working with a table, the
.Columns(2) wont work.
This part hints that you have a table that your are trying to sort.
There's two approaches that I can think of now, to solve this:
1. Sort a regular range by custom list
We can remove the table by:
- Click on the table
- Go to design tab
- Convert to Range
Then your originally code will work (Changed
My girlfriend was asked the below question in an interview:
We trigger 5 independent APIs simultaneously. Once they have all completed, we want to trigger a function. How will you design a system to do this?
My girlfriend replied she will use a flag variable, but the interviewer was evidently not happy with it.
So, is there a good way in which this could be handled (in a distributed context)? Note that each of the 5 API calls are made by different servers and the function to be triggered is on a 6th server....
ANSWERAnswered 2021-Jun-13 at 23:34
If I were asked this, my first thought would be to use promises/futures. The idea behind them is that you can execute time-consuming operations asynchronously and they will somehow notify you when they've completed, either successfully or unsuccessfully, typically by calling a callback function. So the first step is to spawn five asynchronous tasks and get five promises.
Promise.all(); in Java I would use
I would want to make sure to handle both success and failure. The combined promise should succeed if all of the API calls succeed and fail if any of them fail. If any fail there should be appropriate error handling/reporting. What happens if multiple calls fail? How would a mix of successes and failures be reported? These would be design points to mention, though not necessarily solve during the interview.
Promises and futures typically have modular layering system that would allow edge cases like timeouts to be handled by chaining handlers together. If done right, timeouts could become just another error condition that would be naturally handled by the error handling already in place.
This solution would not require any state to be shared across threads, so I would not have to worry about mutexes or deadlocks or other thread synchronization problems.
She said she would use a flag variable to keep track of the number of API calls have returned.
One thing that makes great interviewees stand out is their ability to anticipate follow-up questions and explain details before they are asked. The best answers are fully fleshed out. They demonstrate that one has thought through one's answer in detail, and they have minimal handwaving.
When I read the above I have a slew of follow-up questions:
- How will she know when each API call has returned? Is she waiting for a function call to return, a callback to be called, an event to be fired, or a promise to complete?
- How is she causing all of the API calls to be executed concurrently? Is there multithreading, a fork-join pool, multiprocessing, or asynchronous execution?
- Flag variables are booleans. Is she really using a flag, or does she mean a counter?
- What is the variable tracking and what code is updating it?
- What is monitoring the variable, what condition is it checking, and what's it doing when the condition is reached?
- If using multithreading, how is she handling synchronization?
- How will she handle edge cases such API calls failing, or timing out?
A flag variable might lead to a workable solution or it might lead nowhere. The only way an interviewer will know which it is is if she thinks about and proactively discusses these various questions. Otherwise, the interviewer will have to pepper her with follow-up questions, and will likely lower their evaluation of her.
When I interview people, my mental grades are something like:
- S — Solution works and they addressed all issues without prompting.
- A — Solution works, follow-up questions answered satisfactorily.
- B — Solution works, explained well, but there's a better solution that more experienced devs would find.
- C — What they said is okay, but their depth of knowledge is lacking.
- F — Their answer is flat out incorrect, or getting them to explain their answer was like pulling teeth.
I was asked this question in an interview. I was unable to solve it.
Suppose we an have array
let arr = [4,5,10,9,8].
Suppose I decide to calculate the average of 5 & 9. The average would be 7. So the answer would be numbers greater than 7 i.e 8 9 & 10 should print on the console.
NOTE- We have to find the average of any two elements and then check, not the average of all the numbers. Can someone please help with the logic?...
ANSWERAnswered 2021-Jun-13 at 08:40
For me, it looks like you could get only two results:
- No result if two max values are the same, so no value is greater than the average.
- Only the greatest value if a next smaller value exists.
Another solution could be to select a pair and filter the array basex on the average of the pair.
I've begun learning Go, and I ran into a strange bug, and an even stranger fix for it working on a HackerRack problem:...
ANSWERAnswered 2021-Jun-12 at 06:41
So we have an actually correct answer here, the issue is that you're writing to the boolean but never reading from it. Without the
Println(), it's not used in a conditional or any other expression anywhere that depends on its value, so the assignments to it don't affect the program flow. You could remove all of the lines assigning values to
insideValley and the program would act no differently than it does right now (excepting the Println(), of course, which is why adding that "fixed" the issue).
Go is specifically designed to flag "junk" code like that, that adds nothing to the program flow, as a compiler error (well, in most cases. Unused globals and unused functions are some exceptions to that). Simply add in whatever is supposed to be using that boolean's value (such as a conditional based on its value), and you'll stop getting the "variable unused" error.
And as noted in the comments of Vishwa Ratna's answer, vars do not have to be used in every logical pathway. They only need to be used (ie. read from) in at least one logical pathway.
I got an interview question, how the server manages to not make clients requests intercept with each other?
I couldn't actually answer that, because I didn't find the answer online.
I thought the cause of parrel requests/async calls/concurrency or threading.
But I don't have a real answer for that....
ANSWERAnswered 2021-Jun-11 at 13:49
Not sure if I understood your question right but this article explains the single-threaded model of nodeJS pretty nicely imo (node-js-architecture-single-threaded-event-loop)
NodeJS has a single thread for the event loop. I'm not sure about the specific data structure implementations but every request is added to a queue where it's picked up by the event loop, executed and response sent.
If the request performs blocking IO (or other blocking processes*), the operation is handed over to a different thread, the request is put in some waiting list and the event loop picks up a different request to handle. Once the blocking op is done, the event loop picks up the original request and plus the results of the op, continues processing the request then sends a response.
* If the blocking process is procedurally coded by you, you could end up blocking the event loop causing a DOS. One should use a worker thread for that.
** NodeJS also has the concept of multithreading using the cluster module so there's that but it's still generally considered single-threaded.
I found "ambiguous reference to overloaded definition" while trying to practice scala interview question.
I was trying to find the outcome of following code block which results in compilation error :
ANSWERAnswered 2021-Jun-09 at 13:06
It's because there's no common inferred types and you didn't specify the types for all the
The below is an interview question which I was unable to solve and needs some help.
A Person is playing with paper and during his game he folds the paper vertically in one turn and then horizontally in another turn and repeats the process n number of times. After he's done he cuts the paper vertically and horizontally. The task at hand is to take a number "N" as input and find the count of paper pieces that will be there after cutting the paper vertically and horizontally after folding it n times following the pattern as mentioned above....
ANSWERAnswered 2021-Jun-08 at 11:14
As the comments mentions, you should look for a pattern in the sections (4 corners) and not in the total parts. We will enumerate the corners as a vector like this:
(a (top left),b (top Right) ,c (bottom left) ,d (bottom Right))
Also for sake of consistency and understanding we always fold from right to left in the vertical fold (right half on top of the left half) and from bottom to top in the horizontal fold (bottom half on top of the top half) and we start with horizontal as the first fold we will preform.
first we start with 1 in each corner so when we divide we get the sum of all corners like this:
(1,1,1,1) = 1 + 1 + 1 + 1 = 4 (n = 0)
lets see what will happen in each corner after few runs:
(2,1,2,1) = 2 + 1 + 2 + 1 = 6 (n = 1)
(4,2,2,1) = 4 + 2 + 2 + 1 = 9 (n = 2)
(6,3,4,2) = 6 + 3 + 4 + 2 = 15 (n = 3)
(9,6,6,4) = 9 + 6 + 6 + 4 = 25 (n = 4)
maybe at first its hard to see the relation between but actually the pattern is pretty simple:
(a,b,c,d) -> (a+b,a,c+d,c) when you fold vertically (from right to left)
(a,b,c,d) -> (a+c,b+d,a,b) when you fold horizontally (from bottom to top)
so you can get the recursive relationship and here some simple code in C for this:
How do I get the permutations in for below 4 numbers with only 2 results. Expected pair is [4,4] and [4,4]...
ANSWERAnswered 2021-Jun-06 at 18:40
You're actually using a brute-force approach, which is O(n!). Here's a O(n²) approach:
I had a job interview yesterday, and I was given a coding challenge as the following:...
ANSWERAnswered 2021-Jun-07 at 08:06
The problem is in
No vulnerabilities reported
You can use Interview like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Interview component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page