import { useState } from "react";
const problems = [
// ── BASICS
─────────────────────────────────────────────
─────────────────────
{
id: 1, category: "Basics",
title: "Array Traversal & Sum",
difficulty: "Easy",
description: "Find the sum and average of all
elements in an array.",
code: `#include <iostream>
using namespace std;
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int sum = 0;
for (int i = 0; i < n; i++)
sum += arr[i];
cout << "Sum: " << sum << endl;
cout << "Average: " << (float)sum / n << endl;
return 0;
}`,
keyPoints: ["sizeof(arr)/sizeof(arr[0]) gives
array length", "Cast to float before division for
average", "Traverse using 0-indexed loop"]
},
{
id: 2, category: "Basics",
title: "Find Min & Max",
difficulty: "Easy",
description: "Find the minimum and maximum
element in an unsorted array.",
code: `#include <iostream>
using namespace std;
int main() {
int arr[] = {3, 1, 9, 2, 7, 5};
int n = sizeof(arr) / sizeof(arr[0]);
int minVal = arr[0], maxVal = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < minVal) minVal = arr[i];
if (arr[i] > maxVal) maxVal = arr[i];
}
cout << "Min: " << minVal << ", Max: " << maxVal
<< endl;
return 0;
}`,
keyPoints: ["Initialize min/max with arr[0]",
"Start loop from index 1", "Single pass O(n)"]
},
{
id: 3, category: "Basics",
title: "Reverse an Array",
difficulty: "Easy",
description: "Reverse array in-place using two
pointers.",
code: `#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
int n = sizeof(arr) / sizeof(arr[0]);
int left = 0, right = n - 1;
while (left < right) {
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}`,
keyPoints: ["Two-pointer technique", "Swap using
a temp variable", "Stop when left >= right"]
},
{
id: 4, category: "Basics",
title: "Linear Search",
difficulty: "Easy",
description: "Search for a target element and
return its index, or -1 if not found.",
code: `#include <iostream>
using namespace std;
int linearSearch(int arr[], int n, int target) {
for (int i = 0; i < n; i++)
if (arr[i] == target)
return i;
return -1;
}
int main() {
int arr[] = {4, 2, 9, 7, 1};
int n = sizeof(arr) / sizeof(arr[0]);
int target = 7;
int result = linearSearch(arr, n, target);
if (result != -1)
cout << "Found at index: " << result << endl;
else
cout << "Not found" << endl;
return 0;
}`,
keyPoints: ["O(n) time complexity", "Returns
index on match, -1 otherwise", "Works on unsorted
arrays"]
},
// ── SORTING
─────────────────────────────────────────────
────────────────────
{
id: 5, category: "Sorting",
title: "Bubble Sort",
difficulty: "Easy",
description: "Sort array using bubble sort —
repeatedly swap adjacent elements if out of order.",
code: `#include <iostream>
using namespace std;
void bubbleSort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
bool swapped = false;
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
}
}
if (!swapped) break; // Already sorted
}
}
int main() {
int arr[] = {64, 25, 12, 22, 11};
int n = sizeof(arr) / sizeof(arr[0]);
bubbleSort(arr, n);
for (int i = 0; i < n; i++) cout << arr[i] << "
";
return 0;
}`,
keyPoints: ["O(n²) worst case, O(n) best case
with flag", "Inner loop shrinks each pass (n-i-1)",
"swapped flag = early exit optimization"]
},
{
id: 6, category: "Sorting",
title: "Selection Sort",
difficulty: "Easy",
description: "Find minimum element each pass and
place it at the correct position.",
code: `#include <iostream>
using namespace std;
void selectionSort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
int minIdx = i;
for (int j = i + 1; j < n; j++)
if (arr[j] < arr[minIdx])
minIdx = j;
// Swap found minimum with arr[i]
int temp = arr[minIdx];
arr[minIdx] = arr[i];
arr[i] = temp;
}
}
int main() {
int arr[] = {64, 25, 12, 22, 11};
int n = sizeof(arr) / sizeof(arr[0]);
selectionSort(arr, n);
for (int i = 0; i < n; i++) cout << arr[i] << "
";
return 0;
}`,
keyPoints: ["O(n²) always — no early exit",
"Exactly n-1 swaps total", "Finds minimum index, then
swaps once per pass"]
},
{
id: 7, category: "Sorting",
title: "Insertion Sort",
difficulty: "Easy",
description: "Build sorted portion by inserting
each element into its correct position.",
code: `#include <iostream>
using namespace std;
void insertionSort(int arr[], int n) {
for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}
int main() {
int arr[] = {12, 11, 13, 5, 6};
int n = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, n);
for (int i = 0; i < n; i++) cout << arr[i] << "
";
return 0;
}`,
keyPoints: ["O(n²) worst, O(n) best (nearly
sorted)", "Shifts elements right to make room",
"Stable sort — preserves equal element order"]
},
// ── SEARCHING
─────────────────────────────────────────────
──────────────────
{
id: 8, category: "Searching",
title: "Binary Search",
difficulty: "Medium",
description: "Search in a SORTED array by halving
the search space each step.",
code: `#include <iostream>
using namespace std;
int binarySearch(int arr[], int n, int target) {
int low = 0, high = n - 1;
while (low <= high) {
int mid = low + (high - low) / 2; // Avoids
overflow
if (arr[mid] == target) return mid;
else if (arr[mid] < target) low = mid + 1;
else high = mid - 1;
}
return -1;
}
int main() {
int arr[] = {2, 5, 8, 12, 16, 23};
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Found at index: " << binarySearch(arr,
n, 12) << endl;
return 0;
}`,
keyPoints: ["Array MUST be sorted first", "O(log
n) time complexity", "mid = low + (high-low)/2
prevents integer overflow"]
},
// ── 2D ARRAYS
─────────────────────────────────────────────
──────────────────
{
id: 9, category: "2D Arrays",
title: "Matrix Input & Display",
difficulty: "Easy",
description: "Declare, input, and print a 2D
matrix.",
code: `#include <iostream>
using namespace std;
int main() {
int rows = 3, cols = 3;
int mat[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
cout << "Matrix:" << endl;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++)
cout << mat[i][j] << "\\t";
cout << endl;
}
return 0;
}`,
keyPoints: ["Declared as int mat[rows][cols]",
"Two nested loops: i for rows, j for cols", "\\t for
tabbed formatting"]
},
{
id: 10, category: "2D Arrays",
title: "Matrix Addition",
difficulty: "Easy",
description: "Add two matrices element-by-
element.",
code: `#include <iostream>
using namespace std;
int main() {
int A[2][2] = {{1, 2}, {3, 4}};
int B[2][2] = {{5, 6}, {7, 8}};
int C[2][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
C[i][j] = A[i][j] + B[i][j];
cout << "Result:" << endl;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++)
cout << C[i][j] << " ";
cout << endl;
}
return 0;
}`,
keyPoints: ["Matrices must be same dimensions",
"C[i][j] = A[i][j] + B[i][j]", "O(n²) for n×n
matrix"]
},
{
id: 11, category: "2D Arrays",
title: "Matrix Transpose",
difficulty: "Medium",
description: "Transpose a matrix: rows become
columns.",
code: `#include <iostream>
using namespace std;
int main() {
int mat[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int trans[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
trans[j][i] = mat[i][j]; // Swap i and j!
cout << "Transpose:" << endl;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++)
cout << trans[i][j] << " ";
cout << endl;
}
return 0;
}`,
keyPoints: ["trans[j][i] = mat[i][j] — index swap
is key", "For in-place: only swap upper triangle (j >
i)", "Non-square matrices need separate result
array"]
},
{
id: 12, category: "2D Arrays",
title: "Matrix Multiplication",
difficulty: "Medium",
description: "Multiply two matrices. C[i][j] =
sum of A[i][k]*B[k][j].",
code: `#include <iostream>
using namespace std;
int main() {
int A[2][3] = {{1,2,3},{4,5,6}};
int B[3][2] = {{7,8},{9,10},{11,12}};
int C[2][2] = {0};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 3; k++)
C[i][j] += A[i][k] * B[k][j];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++)
cout << C[i][j] << " ";
cout << endl;
}
return 0;
}`,
keyPoints: ["A is m×n, B must be n×p → result is
m×p", "Three nested loops: i, j, k", "Initialize
result array to 0!"]
},
// ── STRINGS
─────────────────────────────────────────────
────────────────────
{
id: 13, category: "Strings (char[])",
title: "String Length Without strlen",
difficulty: "Easy",
description: "Count characters manually until
null terminator '\\0'.",
code: `#include <iostream>
using namespace std;
int strLen(char s[]) {
int len = 0;
while (s[len] != '\\0')
len++;
return len;
}
int main() {
char str[] = "Hello";
cout << "Length: " << strLen(str) << endl;
return 0;
}`,
keyPoints: ["C-strings end with '\\0' null
terminator", "Loop until you hit '\\0'", "\"Hello\"
has length 5, stored in 6 bytes"]
},
{
id: 14, category: "Strings (char[])",
title: "Check Palindrome String",
difficulty: "Medium",
description: "Check if a string reads the same
forwards and backwards.",
code: `#include <iostream>
#include <cstring>
using namespace std;
bool isPalindrome(char s[]) {
int len = strlen(s);
int left = 0, right = len - 1;
while (left < right) {
if (s[left] != s[right]) return false;
left++;
right--;
}
return true;
}
int main() {
char str[] = "racecar";
if (isPalindrome(str))
cout << str << " is a palindrome" << endl;
else
cout << str << " is not a palindrome" <<
endl;
return 0;
}`,
keyPoints: ["Two-pointer from both ends", "Return
false on first mismatch", "#include <cstring> for
strlen"]
},
// ── ALGORITHMS
─────────────────────────────────────────────
─────────────────
{
id: 15, category: "Algorithms",
title: "Kadane's Algorithm (Max Subarray)",
difficulty: "Hard",
description: "Find the maximum sum contiguous
subarray in O(n).",
code: `#include <iostream>
using namespace std;
int main() {
int arr[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
int n = sizeof(arr) / sizeof(arr[0]);
int maxSum = arr[0], currentSum = arr[0];
for (int i = 1; i < n; i++) {
// Either extend existing subarray or start
fresh
currentSum = max(arr[i], currentSum +
arr[i]);
maxSum = max(maxSum, currentSum);
}
cout << "Max subarray sum: " << maxSum << endl;
// Output: 6
return 0;
}`,
keyPoints: ["O(n) — single pass", "currentSum =
max(arr[i], currentSum + arr[i])", "maxSum tracks
global best; answer is {4,-1,2,1}"]
},
{
id: 16, category: "Algorithms",
title: "Dutch National Flag (Sort 0s, 1s, 2s)",
difficulty: "Hard",
description: "Sort array containing only 0, 1, 2
in one pass using three pointers.",
code: `#include <iostream>
using namespace std;
void dutchFlag(int arr[], int n) {
int low = 0, mid = 0, high = n - 1;
while (mid <= high) {
if (arr[mid] == 0) {
swap(arr[low], arr[mid]);
low++; mid++;
} else if (arr[mid] == 1) {
mid++;
} else { // arr[mid] == 2
swap(arr[mid], arr[high]);
high--; // Don't increment mid!
}
}
}
int main() {
int arr[] = {2, 0, 1, 2, 1, 0};
int n = sizeof(arr) / sizeof(arr[0]);
dutchFlag(arr, n);
for (int i = 0; i < n; i++) cout << arr[i] << "
";
return 0;
}`,
keyPoints: ["3 pointers: low, mid, high", "O(n)
single pass, O(1) space", "When swap with high: DON'T
increment mid"]
},
{
id: 17, category: "Algorithms",
title: "Prefix Sum Array",
difficulty: "Medium",
description: "Build prefix sum array for O(1)
range sum queries.",
code: `#include <iostream>
using namespace std;
int main() {
int arr[] = {3, 1, 4, 1, 5, 9};
int n = sizeof(arr) / sizeof(arr[0]);
int prefix[6];
prefix[0] = arr[0];
for (int i = 1; i < n; i++)
prefix[i] = prefix[i-1] + arr[i];
// Range sum from index l to r (inclusive)
int l = 1, r = 4;
int rangeSum = prefix[r] - (l > 0 ? prefix[l-1] :
0);
cout << "Sum from " << l << " to " << r << ": "
<< rangeSum << endl;
return 0;
}`,
keyPoints: ["prefix[i] = prefix[i-1] + arr[i]",
"Range sum [l,r] = prefix[r] - prefix[l-1]",
"Preprocessing O(n), each query O(1)"]
},
{
id: 18, category: "Algorithms",
title: "Remove Duplicates (Sorted Array)",
difficulty: "Medium",
description: "Remove duplicates in-place from a
sorted array and return new length.",
code: `#include <iostream>
using namespace std;
int removeDuplicates(int arr[], int n) {
if (n == 0) return 0;
int j = 0; // Pointer for unique elements
for (int i = 1; i < n; i++) {
if (arr[i] != arr[j]) {
j++;
arr[j] = arr[i];
}
}
return j + 1; // New length
}
int main() {
int arr[] = {1, 1, 2, 3, 3, 4, 5, 5};
int n = sizeof(arr) / sizeof(arr[0]);
int newLen = removeDuplicates(arr, n);
for (int i = 0; i < newLen; i++) cout << arr[i]
<< " ";
return 0;
}`,
keyPoints: ["Only works efficiently on SORTED
arrays", "j tracks last unique position", "Return j+1
as new length"]
},
{
id: 19, category: "Algorithms",
title: "Rotate Array by K Positions",
difficulty: "Medium",
description: "Rotate array right by k steps using
reversal trick.",
code: `#include <iostream>
using namespace std;
void reverse(int arr[], int l, int r) {
while (l < r) {
int temp = arr[l]; arr[l] = arr[r]; arr[r] =
temp;
l++; r--;
}
}
void rotateRight(int arr[], int n, int k) {
k = k % n; // Handle k > n
reverse(arr, 0, n - 1); // Step 1: reverse
all
reverse(arr, 0, k - 1); // Step 2: reverse
first k
reverse(arr, k, n - 1); // Step 3: reverse
rest
}
int main() {
int arr[] = {1, 2, 3, 4, 5, 6, 7};
int n = 7;
rotateRight(arr, n, 3);
for (int i = 0; i < n; i++) cout << arr[i] << "
"; // 5 6 7 1 2 3 4
return 0;
}`,
keyPoints: ["k % n handles k larger than array
size", "Three reverses: all → first k → remaining",
"O(n) time, O(1) space"]
},
{
id: 20, category: "Algorithms",
title: "Second Largest Element",
difficulty: "Medium",
description: "Find the second largest element in
a single pass.",
code: `#include <iostream>
#include <climits>
using namespace std;
int main() {
int arr[] = {12, 35, 1, 10, 34, 1};
int n = sizeof(arr) / sizeof(arr[0]);
int first = INT_MIN, second = INT_MIN;
for (int i = 0; i < n; i++) {
if (arr[i] > first) {
second = first;
first = arr[i];
} else if (arr[i] > second && arr[i] !=
first) {
second = arr[i];
}
}
if (second == INT_MIN)
cout << "No second largest" << endl;
else
cout << "Second largest: " << second << endl;
return 0;
}`,
keyPoints: ["INT_MIN from <climits> as initial
sentinel", "Update second when new value > second but
!= first", "Handles duplicates with != first check"]
},
];
const categories = ["All", ...new Set([Link](p
=> [Link]))];
const diffColors = { Easy: "#4ade80", Medium:
"#fb923c", Hard: "#f87171" };
export default function App() {
const [activeCategory, setActiveCategory] =
useState("All");
const [openId, setOpenId] = useState(null);
const [copied, setCopied] = useState(null);
const filtered = activeCategory === "All"
? problems
: [Link](p => [Link] ===
activeCategory);
const handleCopy = (code, id) => {
[Link](code);
setCopied(id);
setTimeout(() => setCopied(null), 1800);
};
return (
<div style={{
minHeight: "100vh",
background: "#0f0f12",
fontFamily: "'Courier New', monospace",
color: "#e2e8f0",
padding: "0 0 60px 0"
}}>
{/* Header */}
<div style={{
background: "linear-gradient(135deg, #1a1a2e
0%, #16213e 50%, #0f3460 100%)",
borderBottom: "2px solid #00d4ff33",
padding: "32px 24px 24px",
textAlign: "center"
}}>
<div style={{ fontSize: 13, letterSpacing: 6,
color: "#00d4ff", marginBottom: 8, textTransform:
"uppercase" }}>
Data Structures · C++ Arrays
</div>
<h1 style={{
fontSize: "clamp(24px, 5vw, 42px)",
margin: 0,
fontFamily: "Georgia, serif",
fontWeight: 700,
background: "linear-gradient(90deg, #fff
40%, #00d4ff)",
WebkitBackgroundClip: "text",
WebkitTextFillColor: "transparent"
}}>
Array Problems Prep 🧠
</h1>
<p style={{ color: "#94a3b8", marginTop: 10,
fontSize: 14 }}>
{[Link]} problems — Basics ·
Sorting · Searching · 2D · Algorithms
</p>
</div>
{/* Category Filter */}
<div style={{
display: "flex", flexWrap: "wrap", gap: 8,
padding: "20px 20px 12px", justifyContent:
"center"
}}>
{[Link](cat => (
<button key={cat} onClick={() =>
setActiveCategory(cat)} style={{
padding: "6px 16px",
borderRadius: 20,
border: activeCategory === cat ? "1.5px
solid #00d4ff" : "1.5px solid #334155",
background: activeCategory === cat ?
"#00d4ff18" : "transparent",
color: activeCategory === cat ? "#00d4ff"
: "#94a3b8",
cursor: "pointer",
fontSize: 13,
fontFamily: "inherit",
transition: "all 0.2s"
}}>
{cat}
</button>
))}
</div>
{/* Problem count */}
<div style={{ textAlign: "center", color:
"#475569", fontSize: 12, marginBottom: 16 }}>
showing {[Link]}
problem{[Link] !== 1 ? "s" : ""}
</div>
{/* Problem Cards */}
<div style={{ maxWidth: 820, margin: "0 auto",
padding: "0 16px", display: "flex", flexDirection:
"column", gap: 12 }}>
{[Link](p => {
const isOpen = openId === [Link];
return (
<div key={[Link]} style={{
background: "#13131a",
border: isOpen ? "1.5px solid
#00d4ff55" : "1.5px solid #1e293b",
borderRadius: 12,
overflow: "hidden",
transition: "border-color 0.2s"
}}>
{/* Card Header */}
<div
onClick={() => setOpenId(isOpen ?
null : [Link])}
style={{
display: "flex", alignItems:
"center",
justifyContent: "space-between",
padding: "14px 18px", cursor:
"pointer",
userSelect: "none"
}}
>
<div style={{ display: "flex",
alignItems: "center", gap: 12 }}>
<span style={{
fontSize: 11, color: "#475569",
minWidth: 22, fontVariantNumeric:
"tabular-nums"
}}>
{String([Link]).padStart(2, "0")}
</span>
<div>
<div style={{ fontSize: 15,
fontWeight: 600, color: "#e2e8f0" }}>{[Link]}</div>
<div style={{ fontSize: 11,
color: "#64748b", marginTop: 2 }}>{[Link]}</div>
</div>
</div>
<div style={{ display: "flex",
alignItems: "center", gap: 10 }}>
<span style={{
fontSize: 11, padding: "2px
10px",
borderRadius: 10,
background:
diffColors[[Link]] + "22",
color: diffColors[[Link]],
border: "1px solid " +
diffColors[[Link]] + "55"
}}>
{[Link]}
</span>
<span style={{ color: "#475569",
fontSize: 18, lineHeight: 1 }}>
{isOpen ? "▲" : "▼"}
</span>
</div>
</div>
{/* Expanded Content */}
{isOpen && (
<div style={{ borderTop: "1px solid
#1e293b" }}>
{/* Description */}
<div style={{ padding: "14px 18px
0", color: "#94a3b8", fontSize: 13, lineHeight: 1.6
}}>
{[Link]}
</div>
{/* Key Points */}
<div style={{ padding: "12px 18px
0" }}>
<div style={{ fontSize: 11,
color: "#00d4ff", letterSpacing: 2, marginBottom: 8
}}>KEY POINTS</div>
{[Link]((kp, i) => (
<div key={i} style={{ display:
"flex", gap: 8, marginBottom: 4, fontSize: 12, color:
"#cbd5e1" }}>
<span style={{ color:
"#00d4ff" }}>›</span>
<span>{kp}</span>
</div>
))}
</div>
{/* Code Block */}
<div style={{ padding: "14px 18px
18px" }}>
<div style={{ display: "flex",
justifyContent: "space-between", alignItems:
"center", marginBottom: 8 }}>
<span style={{ fontSize: 11,
color: "#475569", letterSpacing: 2 }}>C++ CODE</span>
<button
onClick={() =>
handleCopy([Link], [Link])}
style={{
background: copied === [Link]
? "#00d4ff22" : "#1e293b",
border: "1px solid " +
(copied === [Link] ? "#00d4ff" : "#334155"),
color: copied === [Link] ?
"#00d4ff" : "#94a3b8",
padding: "4px 12px",
borderRadius: 6,
fontSize: 11,
cursor: "pointer",
fontFamily: "inherit",
transition: "all 0.2s"
}}
>
{copied === [Link] ? "✓
Copied!" : "Copy"}
</button>
</div>
<pre style={{
background: "#0a0a10",
border: "1px solid #1e293b",
borderRadius: 8,
padding: "16px",
overflowX: "auto",
fontSize: 12.5,
lineHeight: 1.6,
margin: 0,
color: "#e2e8f0",
tabSize: 4
}}>
<code>{[Link]}</code>
</pre>
</div>
</div>
)}
</div>
);
})}
</div>
{/* Footer */}
<div style={{ textAlign: "center", marginTop:
40, color: "#334155", fontSize: 12 }}>
good luck on the test 💙
</div>
</div>
);
}