0% found this document useful (0 votes)
2 views3 pages

Array Master Notes Full Part 1 2 3 With Java

Uploaded by

kabir000356
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Array Master Notes Full Part 1 2 3 With Java

Uploaded by

kabir000356
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ARRAY MASTER NOTES – FULL INTERVIEW GUIDE

(PART 1 + 2 + 3)

This PDF contains complete array preparation from basic to advanced level with multiple
approaches and Java implementations.

PART 1 – BASICS & COUNTING

1. Count Even & Odd Elements in Array

Approach: Traverse array and maintain counters. Time O(n), Space O(1).

int even=0, odd=0; for(int x : arr){ if(x % 2 == 0) even++; else odd++; }

2. Find Maximum & Minimum Element

Approach: Linear traversal. Time O(n).

int max = arr[0], min = arr[0]; for(int i=1;i max) max = arr[i]; if(arr[i] < min)
min = arr[i]; }

3. Sum & Average of Array

int sum = 0; for(int x : arr) sum += x; double avg = (double)sum / n;


PART 2 – SEARCHING & DUPLICATES

4. Linear Search

for(int i=0;i

5. Binary Search (Sorted Array)

int l=0, r=n-1; while(l <= r){ int mid = (l+r)/2; if(arr[mid] == key) break; else
if(arr[mid] < key) l = mid+1; else r = mid-1; }

6. Remove Duplicates from Sorted Array

Two pointer approach. Time O(n), Space O(1).

int j = 0; for(int i=1;i


PART 3 – REARRANGEMENT, ROTATION & SUBARRAY

7. Reverse an Array (Two Pointer)

int l=0, r=n-1; while(l < r){ int temp = arr[l]; arr[l] = arr[r]; arr[r] = temp;
l++; r--; }

8. Move All Zeros to End

int j = 0; for(int i=0;i

9. Rotate Array using Reversal Algorithm

// Left rotate by d reverse(arr, 0, d-1); reverse(arr, d, n-1); reverse(arr, 0,


n-1);

10. Maximum Subarray Sum – Kadane’s Algorithm

int maxSum = arr[0], currSum = arr[0]; for(int i=1;i

11. Equilibrium Index

int total = 0; for(int x : arr) total += x; int leftSum = 0; for(int i=0;i

Prepared for Interviews – Explain brute force first, then optimized approach.

You might also like