interview | Interview questions
kandi X-RAY | interview Summary
kandi X-RAY | interview Summary
Interview questions
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Start phase .
- Returns the largest multiple of the given array
- Checks if the input is schedramble
- Returns the max chain of two nodes .
- Returns the longest palindic char in linear form .
- Gets the equation .
- Justify one word .
- Justify words .
- Finds sub - square in the input string .
- Get the skyline for the given buildings
interview Key Features
interview Examples and Code Snippets
def set(self, results, query):
"""Set the result for the given query key in the cache.
When updating an entry, updates its position to the front of the LRU list.
If the entry is new and the cache is at capacity, removes the o
def within_past_week(self, timestamp):
"""Return True if timestamp is within past week, False otherwise."""
...
def extract_max_priority_page(self):
"""Return the highest priority link in `links_to_crawl`."""
pass
Community Discussions
Trending Discussions on interview
QUESTION
A few days ago in an interview, i was asked to explain following cases:
...ANSWER
Answered 2021-Jun-15 at 12:54You 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 p
is Parent
in both cases because it is declared as Parent p
. No matter what you assign it. You may even assign it null
.
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 p
was null
.
It is okay to assign a Child
to a Parent
, because the Child
class derives from Parent
. A Child
is therefore a Parent
(in OO terms).
However, a Parent
is not a Child
, because it does not derive from it. Therefore, in the second case, you cannot cast p
to 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 Child
from 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.
See also: The Stack Is An Implementation Detail, Part One and Two (Eric Lippert's blog)
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:
QUESTION
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:
...ANSWER
Answered 2021-Jun-11 at 21:02The 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 Key1:=.Columns(2)
):
QUESTION
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.
...ANSWER
Answered 2021-Jun-13 at 23:34If 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.
Then I would join the five promises together, creating a unified promise that represents the five separate tasks. In JavaScript I might call Promise.all()
; in Java I would use CompletableFuture.allOf()
.
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.
QUESTION
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]
.
Write a code in JavaScript to print numbers that are greater than the average of any two elements of the given array.
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?
...ANSWER
Answered 2021-Jun-13 at 08:40For 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.
QUESTION
I've begun learning Go, and I ran into a strange bug, and an even stranger fix for it working on a HackerRack problem:
...ANSWER
Answered 2021-Jun-12 at 06:41So 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.
QUESTION
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.
...ANSWER
Answered 2021-Jun-11 at 13:49Not 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)
tldr:
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.
QUESTION
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 :
Code :
...ANSWER
Answered 2021-Jun-09 at 13:06It's because there's no common inferred types and you didn't specify the types for all the Either
.
So
QUESTION
The below is an interview question which I was unable to solve and needs some help.
Question:
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.
...ANSWER
Answered 2021-Jun-08 at 11:14As 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)
and
(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:
QUESTION
How do I get the permutations in for below 4 numbers with only 2 results. Expected pair is [4,4] and [4,4]
...ANSWER
Answered 2021-Jun-06 at 18:40You're actually using a brute-force approach, which is O(n!). Here's a O(n²) approach:
QUESTION
I had a job interview yesterday, and I was given a coding challenge as the following:
...ANSWER
Answered 2021-Jun-07 at 08:06The problem is in
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install interview
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 .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page