iOS

Two Sum Problem

[Question] : Given an array of integers nums and an integer target, find indices of the two numbers which addition equals to target.Example: Input: nums = [2,7,11,15], target = 13 Output: [0,2] Explanation: Because nums[0] + nums[2] == 13, we return [0, 2]. Approach #1 : Using Two pointers: – Step 1: First sort array thenStep 2: If arr[left] […]

Two Sum Problem Read More »

How to Find a number which appears once and other numbers are twice ?

[Question]: In a given random array find a number which appears only single time Example : Random array input – [9,2,2,3,4,4,3] output = 9Solution: Step 1: Create a dictionary. Step 2: Create loop and fill the keys with element occurrence.Step 3: Create a loop and return the dictionary element which has only single occurrence .T

How to Find a number which appears once and other numbers are twice ? Read More »

Quick Sort

Logic: Create a pivot element & arrange elements with two partitions, If the elements are lesser than pivot add it to left partition & if elements bigger than the pivot arrange it to right side of partition & make call recursively with the subarray found with same approach. Time Complexity: Avg O(n^2) .. Best: O(n

Quick Sort Read More »