Problem:- Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Solution:- Summary of the problem:- Here we have to search in the given sorted array that if the given number…
Category: Java Programming Exercises, Solution
Leetcode 27 Java Solution: Remove Element
Problem Statement:- Given an array nums and a value val, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn’t matter what you leave beyond…
Merge Two Sorted Lists : Leet Code Solution
Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. Ans:- To solve this approach, we will create a Dummy Head. And as the two given list will be sorted, so we have to only compare the individual…