This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a sorted array nums, write a function to remove the | |
// duplicates from the array such that each element appears | |
// only once. Your function should return the new length | |
const removeDuplicateArrayElements = (nums) => { | |
const noDuplicatesArray = []; | |
for(let i = 0; i < nums.length; i++){ | |
//compare adjacent elements of the array and check if they | |
//are the same since the array is sorted already, skip if true. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given an array nums, and a value val, write a function to remove | |
// all instances of val from the array and return the new length | |
const removeValInstances = (arr, val) => { | |
if(!arr) return 0; | |
if(!Array.isArray(arr)) return 0; | |
if(!val) return arr.length; | |
let newArrLength = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A school has two classes A and B. Each class has the ages of its students in | |
// a sorted list. | |
// The school decides to join both classes and needs you to help them write a function | |
// that merges both lists into one such that the students' ages still remain | |
// sorted in an increasing order | |
// PS: Do not use in buit sort function | |