frontend-interviewing icon indicating copy to clipboard operation
frontend-interviewing copied to clipboard

refactor: added comments for understanding the question better around array being sorted and not allowing duplicates

Open vivek12345 opened this issue 3 years ago • 0 comments

Issue https://github.com/young/frontend-interviewing/issues/12

What is the current behavior?

  • In the current question for shared numbers, we do not explicitly mention that the array is sorted and that it won't contain duplicate elements.
  • The answer to the solution increments only the xIterator but it should be incrementing the yIterator too since both values were same. This is important for scenario with duplicate values. For example
const x = [4, 4, 8, 9, 9];
const y = [4, 5, 9]

In the above problem technically the output should be [4, 9] but in the current implementation it will be [4, 4, 9]

What is the new behavior?

  • In this PR, I have refactored the question to include information around array being sorted and not containing duplicates.
  • In this PR, I have also added a fix to the answer where increment both x and y pointers when values are same.

Checklist:

  • [x] Documentation
  • [ ] Tests N/A
  • [x] Ready to be merged

vivek12345 avatar Jun 25 '21 01:06 vivek12345