Suppose an array sorted in ascending order is rotated at home pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). you are given a target value to search. if found in the array return its index, otherwise return -1. you may assume no duplicate exists in the array. your algorithm’s runtime complexity must be…

# Category: Array

Arrays are nicely organized lists of data. The array is a collection of homogeneous data types.

Think of a numbered list that starts at zero and extends one line every time you add something to the list. The arrays are useful for any number of situations because they’re treated as a single chunk of data. The array is one of the most important parts of any programming language.

For instance, if you wanted to store a bunch of high scores for that you want to do that with an array.

## Find First And Last Position of Element in sorted Array

given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. your algorithm’s runtime complexity must be in the order of 0(log n). if the target is not found in the array, return [-1,-1]. Example 1: input: nums = [5,7,7,8,8,10], target = 8 output: [3,4]…

## 3sum in Java

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? find all unique triplets in the array which gives the sum of zero. note: the solution set must not contain duplicate triplets. Example: given array nums = [-1, 0, 1, 2,-1,…

## Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively. find the median of the two sorted arrays. The overall run time complexity should be 0(log (m+n)). you may assume nums1 and nums2 cannot be both empty. Example 1: nums1 = [1, 3] nums2 = [2] the median is 2.0 Example…

## HOW TO GET DISTINCT ELEMENTS FROM AN ARRAY BY AVOIDING DUPLICATE ELEMENTS?

Here we explain how to find distinct elements from an array by avoiding duplicate elements. In the below program we use array of integers int num[], in this array we found distinct elements. For finding the distinct elements we use the following two ways. Program: Find distinct elements from an array Output: following is the…