coding-interview | code interview questions , including Swordsman Offer | Learning library
kandi X-RAY | coding-interview Summary
kandi X-RAY | coding-interview Summary
😀 A collection of code interview questions, including Swordsman Offer, Beauty of Programming, etc.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of coding-interview
coding-interview Key Features
coding-interview Examples and Code Snippets
public static int divide(int a, int b) throws java.lang.ArithmeticException {
if (b == 0) {
throw new java.lang.ArithmeticException("ERROR: Divide by zero.");
}
int absa = abs(a);
int absb = abs(b);
int product = 0;
int x = 0;
whi
public void escalateAndReassign() {
if (currentCall != null) {
/* escalate call */
currentCall.incrementRank();
callHandler.dispatchCall(currentCall);
/* free the employee */
currentCall = null;
}
/* assign a new call */
assi
public static Graph buildGraph(String[] projects, String[][] dependencies) {
Graph graph = new Graph();
for (String[] dependency : dependencies) {
String first = dependency[0];
String second = dependency[1];
graph.addEdge(first, secon
Community Discussions
Trending Discussions on coding-interview
QUESTION
https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-5-smallest-multiple
I am solving Project Euler and this is the solution I came up with for the 5th question. It passes the first 5 test cases but fails at the last one. smallestMult(20)
I believe it is happening because the number gets too big when n>=17
. (it is working in the codesnippet here without a problem)
ANSWER
Answered 2021-Aug-08 at 15:07Your solution works however is less efficient. You can try this method:
QUESTION
I am trying to write an implementation on C# of Subsets pattern read here 14 Patterns to Ace Any Coding Interview Question:
It looks obvious but confuses me. My research says me it should be implemented via Jagged Arrays (not Multidimensional Arrays). I started:
...ANSWER
Answered 2021-May-27 at 14:44What I find easiest is translating the problem from a word problem into a more logical one.
Start with an empty set : [[]]
So the trick here is that this word problem tells you to create an empty set but immediately shows you a set that contains an element.
If we break this down into arrays instead(because I personally find it more intuitive) we can translate it to:
Start with an array of arrays, who's first element is an empty array. (instead of
null
)
So basically
QUESTION
I've got working code, but I'm looking to improve the way I understand and implement different coding techniques as a whole. I thought this problem presented a good chance to get feedback on what I'm doing.
The idea here is to take two arguments, an array and an integer. Identify all pairs in the array that sum to make the integer argument, and then return the sum of the indices. You cannot reuse an index, and you must always use the smallest index available to you. There is an explanation on the FCC code guide here: https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/pairwise
So - here is the question. Is there any good way of doing this without using nested for loops? I am becoming increasingly aware of time/space complexities, and I know that O(n^2) won't land me the job. I would imagine a hashmap of some sort would come into it, but I just don't have the experience and knowledge to know how to use them.
Here is the code:
...ANSWER
Answered 2020-Jun-19 at 15:48For a better performance you can save the arr.length into a variable, then for loop won't count every single loop.
QUESTION
The Coding Question which I am trying to solve is this. I tried to solve but not all the test cases passed I am not able to find what could be the reason?
Identify possible words: Detective Bakshi while solving a case stumbled upon a letter which had many words whose one character was missing i.e. one character in the word was replaced by an underscore. For e.g.“Fi_er”. He also found thin strips of paper which had a group of words separated by colons, for e.g. “Fever:filer:Filter:Fixer:fiber:fibre:tailor:offer”. He could figure out that the word whose one character was missing was one of the possible words from the thin strips of paper. Detective Bakshi has approached you (a computer programmer) asking for help in identifying the possible words for each incomplete word.
You are expected to write a function to identify the set of possible words. The function identifyPossibleWords takes two strings as input where,
input1 contains the incomplete word, and input2 is the string containing a set of words separated by colons.
The function is expected to find all the possible words from input2 that can replace the incomplete word input1, and return the result in the format suggested below.
Example1 -
input1 = “Fi_er” input2 = “Fever:filer:Filter:Fixer:fiber:fibre:tailor:offer”
output string should be returned as “FILER:FIXER:FIBER” Note that –
The output string should contain the set of all possible words that can replace the incomplete word in input1 all words in the output string should be stored in UPPER-CASE all words in the output string should appear in the order in which they appeared in input2, i.e. in the above example we have FILER followed by FIXER followed by FIBER. While searching for input1 in input2, the case of the letters are ignored, i.e “Fi_er” matches with “filer” as well as “Fixer” as well as “fiber”. IMPORTANT: If none of the words in input2 are possible candidates to replace input1, the output string should contain the string “ERROR-009” Assumption(s):
Input1 will contain only a single word with only 1 character replaced by an underscore “_” Input2 will contain a series of words separated by colons and NO space character in between Input2 will NOT contain any other special character other than underscore and alphabetic characters.
My solution for the question is:
...ANSWER
Answered 2020-Jun-12 at 14:47There are many ways to achieve the result as expected in the mentioned problem. Since; you've mentioned regex
in the tag; therefore I'll try to provide a possible solution using regex. Although; this can be achieved without them too.
Proposed Procedure:
QUESTION
Trying to solve freecodecamp's symmetric difference challenge (https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/find-the-symmetric-difference), I wrote the following function:
...ANSWER
Answered 2020-May-28 at 14:35In your else
block, you need to return symdiff
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install coding-interview
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