Posts

Reverse a LinkedList

  https://leetcode.com/problems/reverse-linked-list/submissions/971720915/ https://www.youtube.com/watch?v=S9kMVEUg-x4&ab_channel=Codevolution var reverseList = function ( head ) { let prev = null ; let current = head ; while ( current !== null ) { let next = current . next ; current . next = prev ; prev = current ; current = next ; } return prev } ;

Linked List

Image
 A type of Data Structure Orderd Data Structure Organized Data made up of many nodes Nodes   Nodes are just a container for some data, Data can be of type Strings, Numbers, Boolean, Objects LinkedList -  A linked list contains many nodes.

Leetcode Problems

Longest Common Prefix  https://leetcode.com/problems/longest-common-prefix/description/ Valid Parentheses https://leetcode.com/problems/valid-parentheses/ Palindrome Number https://leetcode.com/problems/palindrome-number/

TWO SUM

BLIND 75   Leetcode- Two sum var twoSum = function(nums, target) {     debugger     let map={}     for(let i=0;i<nums.length;i++){          let req = target-nums[i];         if(map[req] !==undefined){             return [i,map[req]]         }         else{            map[nums[i]]=i;          } const nums =[2,7,11,15] ; const target=9;     twoSum(nums,target)

Arguments Passed in Functions

https://leetcode.com/problems/return-length-of-arguments-passed/editorial/ We need to count the number of arguments passed to function  argumentsLength . Here the arguments are passsed in the form of rest parameters. why do we need to pass it like that?  the rest parameter is a feature that allows a function to accept an indefinite number of arguments The rest parameter collects all the remaining arguments passed to a function into an array even if the number of arguments is not known in advance. If no additional arguments are passed, the rest parameter will be an empty array Syntax: function functionName ( ... args ) { // Function body } conventionally named  args  or  rest  to indicate its purpose. function sum ( ... args ) { let total = 0 ; for ( let number of args ) { total += number ; } return total ; } console . log ( sum ( 1 , 2 , 3 , 4 ) ) ; // Output: 10 console . log ( sum ( 5 , 10 , 15 ) ) ; // Output...