New answers tagged

2

From my experience, this is a good first cut solution for a less experienced candidate as opposed to some experienced candidate. Also, a lot of other info is missing in question such as was there any further discussion on how to improve the solution or about adapting some good practices or how to make this code bug free etc. I will try to list down possible ...


1

After getting detailed feedback from the company, below given is the solution which company expected. This also matched with all the points which nik has explained (the accepted answer above). Create a class with 2 different methods. One to update the average (setAverage here) used by company X and other to get the average (getAverage here) which can be ...


0

without the use of 2-d matrix n =int(input()) for i in range(n): temp = n for j in range(i): print(temp,end='') temp = temp -1 for j in range(2*n-2*i - 1): print(n-i,end = '') for j in range(i): temp = temp+1 print(temp,end= '') print() for i in range(n-1,0,-1): temp = n for j in range(i-...


3

const mergeSortedArrays = (arr1, arr2) => [...arr1, ...arr2].sort((a,b) => a-b); const ar1 =[-7, 2, 4, 22, 66, 99]; const ar2 = [1, 5, 9, 88]; console.log( mergeSortedArrays(ar1, ar2) ); // [ -7, 1, 2, 4, 5, 9, 22, 66, 88, 99 ] I don't know if it's not too simple solution, but one-line Arrow function solves this problem... OR in your code instead ...


4

I think considering approach that you chose, your code is alright. A few points: What I don't like is that you get error when passing 2 empty arrays? Why would you do that? Imagine I am generating arrays of different sizes and using your code to merge and sometimes I would pass 2 empty arrays. Should I really need to handle that as special case in my code? ...


2

This is a good first-cut solution to the functional requirement of stated question. However, when you look at it as production code related to two companies (X and Y) these points arise: Monolithic: The code should be well demarcated across X and Y company logic. A single analytics function is processing all of the logic with an (admittedly, nice) value ...


1

Just one remark: do not copy-paste code and then change one tiny bit of it. This indicates that you should create a method. What I mean is this: var newPoint = new CustomPoint(pointToProcess.Column, pointToProcess.Row + 1); grid[newPoint.Row, newPoint.Column] = 1; toPropagateInNextGeneration.Enqueue(newPoint); Those three lines are always the same, except ...


4

All paths do not return def canJumpPos(pos): if pos >= len(nums): return False elif pos in memo: return memo[pos] else: for i in range(nums[pos], 0, -1): if canJumpPos(i + pos): return True memo[pos] = False # Missing Return This ...


1

Your applyOperator consists solely of a switch statement. Rather than having them all assign to firstNum, then returning the value, you might as well directly return the result... private static int applyOperator(char operand, int firstNum, int secondNum){ switch (operand) { case '*': return firstNum * secondNum; case '/': ...


7

What I am entirely missing from your implementation is any correctness checks on the input of roman numerals. This makes it possible to reverse Roman literals, for instance, without any indication that they are invalid. Even if there are bad characters or lowercase characters the program will just crash. That's not any way to behave. One little trick I used ...


10

Try to use more Python idioms; in particular, make your code more declarative rather than imperative. You can rewrite everything after your dictionary definitions with return sum(values[i] for i in s)+sum(checks.get(s[i:i+2], 0) for i in range(len(s)-1)) or, which is more PEP-8 friendly, result = sum(values[i] for i in s) result += sum(checks.get(s[i : i +...


16

Don't use sum as a variable. Especially because you want to use it with your approach! sum = 0 for i in s: sum += values[i] could become: number = sum(values[i] for i in s) s[i] is a string. s[i] + s[i+1] is a string. There is no need to use str() to convert what is already a string to a string. But s[i:i+2] is easier still. With 3999 as the ...


Top 50 recent answers are included