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

Array Patterns

Uploaded by

a2113853210
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 views4 pages

Array Patterns

Uploaded by

a2113853210
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

Beginner Array Patterns – Step by Step Complete

Sheet
This document covers ALL beginner array patterns. Only arrays, loops, and conditions are required.
Follow patterns in order.

1. Linear Traversal
When to use: Use when you need max, min, sum, count, or validation in a single pass.

• Find Largest Element


[Link]
Asked in: TCS, Infosys

• Check if Array is Sorted


[Link]
Asked in: Wipro

• Count Even Numbers


[Link]
Asked in: Capgemini

2. Reverse Array
When to use: Use for reversing, palindrome checks, and as a base for rotation.

• Reverse Array
[Link]
Asked in: Accenture

• Valid Palindrome
[Link]
Asked in: Infosys

• Reverse an Array
[Link]
Asked in: TCS

3. Array Rotation
When to use: Use when circular left/right shifting is required.

• Rotate Array by K
[Link]
Asked in: Cognizant

• Left Rotate by One


[Link]
Asked in: Wipro
• Check Rotated Sorted Array
[Link]
Asked in: Capgemini

4. Frequency Counting
When to use: Use when counting occurrences, duplicates, or majority.

• Majority Element
[Link]
Asked in: TCS

• First Unique Element


[Link]
Asked in: HCL

• Frequency of Elements
[Link]
Asked in: Infosys

5. Second Largest / Smallest


When to use: Use ranking logic without sorting.

• Second Largest Element


[Link]
Asked in: Infosys

• Second Smallest Element


[Link]
Asked in: Wipro

• Largest & Second Largest


[Link]
Asked in: TCS

6. Move / Rearrangement
When to use: Use when repositioning elements while keeping order.

• Move Zeroes
[Link]
Asked in: Amazon

• Move Negatives to One Side


[Link]
space/
Asked in: Flipkart

• Segregate Even and Odd


[Link]
Asked in: TCS
7. Validation Pattern
When to use: Use for checking array conditions and neighbour comparison.

• Valid Mountain Array


[Link]
Asked in: Microsoft

• Non-Decreasing Array
[Link]
Asked in: Infosys

• Check Sorted Array


[Link]
Asked in: Wipro

8. Merge Two Arrays


When to use: Use when combining sorted arrays.

• Merge Sorted Array


[Link]
Asked in: Amazon

• Union of Arrays
[Link]
Asked in: TCS

• Merge Without Extra Space


[Link]
Asked in: Accenture

9. Subarray (Brute Force)


When to use: Use for small constraints and fundamentals.

• Print All Subarrays


[Link]
Asked in: Infosys

• Maximum Subarray
[Link]
Asked in: Wipro

• Count Subarrays
[Link]
Asked in: TCS

10. Sliding Window (Fixed Size)


When to use: Use for contiguous subarray of fixed size k.
• Max Sum Subarray Size K
[Link]
Asked in: Amazon

• Maximum Average Subarray


[Link]
Asked in: Google

• Sliding Window Basics


[Link]
Asked in: Infosys

11. Prefix Sum


When to use: Use for fast range queries after preprocessing.

• Running Sum
[Link]
Asked in: Amazon

• Range Sum Query


[Link]
Asked in: Microsoft

• Subarray Sum Equals K


[Link]
Asked in: Google

12. Missing / Duplicate (1…N)


When to use: Use when elements lie in fixed range.

• Missing Number
[Link]
Asked in: Amazon

• Find the Duplicate Number


[Link]
Asked in: Google

• First Missing Positive


[Link]
Asked in: Microsoft

You might also like