give integer array nums integer val remove occurrence val num inplace the relative order element changedsince impossible change length array language instead result place array num more formally k element remove duplicate k element num hold final result it matter leave k elementsReturn k place final result k slot numsDo allocate extra space array you modify input array inplace O1 extra memoryCustom JudgeThe judge test solution follow codeint num Input arrayint val value removeint expectednum the expected answer correct length it sort value equal valint k removeelementnum val Calls implementationassert k expectednumslengthsortnum 0 k Sort k element numsfor int 0 actuallength assert numsi expectednumsiif assertion pass solution accept Example 1input num 3223 val 3Output 2 num 22__explanation your function return k 2 element num 2It matter leave return k underscoresExample 2input num 01223042 val 2output 5 num 01403___Explanation your function return k 5 element num contain 0 0 1 3 4note element return orderit matter leave return k underscore Constraints0 numslength 1000 numsi 500 val 100