// Function to check if the array can be built using subarrays of prefix
public static boolean canBuild(int[] prefix, int[] arr) {
List<Integer> list = new ArrayList<>();
for (int num : prefix) list.add(num);
int i = prefix.length;
while (i < arr.length) {
boolean matched = false;
// Try all subarrays of prefix
for (int start = 0; start < prefix.length; start++) {
for (int end = start + 1; end <= prefix.length; end++) {
List<Integer> sub = list.subList(start, end);
if (i + sub.size() <= arr.length) {
boolean same = true;
for (int j = 0; j < sub.size(); j++) {
if (arr[i + j] != sub.get(j)) {
same = false;
break;
}
}
if (same) {
i += sub.size();
matched = true;
break;
}
}
}
if (matched) break;
}
if (!matched) return false;
}
return true;
}
public static int findMinOriginalLength(int[] arr) {
for (int len = 1; len <= arr.length; len++) {
int[] prefix = Arrays.copyOfRange(arr, 0, len);
if (canBuild(prefix, arr)) {
return len;
}
}
return arr.length;
}
public static void main(String[] args) {
int[] arr = {5, 4, 7, 2, 7, 4, 4, 7, 7, 2};
int result = findMinOriginalLength(arr);
System.out.println(result);
}
}
4
CODING SOLUTION - Placement Jobs & Materials pinned ยซ// Function to check if the array can be built using subarrays of prefix public static boolean canBuild(int[] prefix, int[] arr) { List<Integer> list = new ArrayList<>(); for (int num : prefix) list.add(num); int i = prefix.length;โฆยป
๐ Here is a Previous Year Coding Question asked in Wipro / Cognizant placement test:
### Question 1: Count Frequency of Words in a Sentence
Problem:
Write a program that takes a sentence and prints the frequency of each word, sorted alphabetically.
Input:
Expected Output:
Python Code:
---
### Question 2: Check if a Matrix is Symmetric
Problem:
Write a program to check if a square matrix is symmetric (i.e., matrix[i][j] == matrix[j][i]).
Input:
Output:
Python Code:
### Question 1: Count Frequency of Words in a Sentence
Problem:
Write a program that takes a sentence and prints the frequency of each word, sorted alphabetically.
Input:
"the quick brown fox jumps over the lazy dog"Expected Output:
brown: 1
dog: 1
fox: 1
jumps: 1
lazy: 1
over: 1
quick: 1
the: 2Python Code:
def count_word_frequency(sentence):
# Remove punctuation and convert to lowercase
sentence = sentence.lower()
# Split the sentence into words
words = sentence.split()
# Create a dictionary to store frequency
frequency = {}
for word in words:
if word in frequency:
frequency[word] += 1
else:
frequency[word] = 1
# Sort dictionary by key (alphabetically)
for word in sorted(frequency):
print(f"{word}: {frequency[word]}")
# Example
input_sentence = "the quick brown fox jumps over the lazy dog the"
count_word_frequency(input_sentence)
---
### Question 2: Check if a Matrix is Symmetric
Problem:
Write a program to check if a square matrix is symmetric (i.e., matrix[i][j] == matrix[j][i]).
Input:
[
[1, 2, 3],
[2, 4, 5],
[3, 5, 6]
]
Output:
The matrix is symmetric.Python Code:
def is_symmetric(matrix):
n = len(matrix)
for i in range(n):
for j in range(n):
if matrix[i][j] != matrix[j][i]:
return False
return True
# Example matrix
matrix = [
[1, 2, 3],
[2, 4, 5],
[3, 5, 6]
]
if is_symmetric(matrix):
print("The matrix is symmetric.")
else:
print("The matrix is not symmetric.")
CODING SOLUTION - Placement Jobs & Materials pinned ยซ๐ Here is a Previous Year Coding Question asked in Wipro / Cognizant placement test: ### Question 1: Count Frequency of Words in a Sentence Problem: Write a program that takes a sentence and prints the frequency of each word, sorted alphabetically.โฆยป
from collections import deque
def heat_spread(grid):
n = len(grid)
m = len(grid[0])
new_grid = [row[:] for row in grid]
directions = [(-1,0), (1,0), (0,-1), (0,1)]
for i in range(n):
for j in range(m):
if grid[i][j] == 'H':
for dx, dy in directions:
ni, nj = i + dx, j + dy
if 0 <= ni < n and 0 <= nj < m and grid[ni][nj] == '.':
new_grid[ni][nj] = 'H'
return new_grid
def simulate_heat(grid, start_x, start_y, end_x, end_y):
n = len(grid)
m = len(grid[0])
queue = deque()
visited = set()
queue.append((start_x, start_y, 0, grid))
visited.add((start_x, start_y))
while queue:
x, y, days, curr_grid = queue.popleft()
if (x, y) == (end_x, end_y):
return days
next_grid = heat_spread(curr_grid)
directions = [(-1,0), (1,0), (0,-1), (0,1)]
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < n and 0 <= ny < m and next_grid[nx][ny] == '.' and (nx, ny) not in visited:
visited.add((nx, ny))
queue.append((nx, ny, days + 1, next_grid))
return -1
# Input Format
n = int(input())
grid = []
for _ in range(n):
grid.append(list(input().strip()))
start_x, start_y = map(int, input().split())
end_x, end_y = map(int, input().split())
print(simulate_heat(grid, start_x, start_y, end_x, end_y))
City Heatwave โ Codevita
PYTHON
#include <iostream>
#include <vector>
using namespace std;
vector<int> p;
int f(int x) {
if (p[x] == x) return x;
return p[x] = f(p[x]);
}
void m(int x, int y) {
int rx = f(x);
int ry = f(y);
if (rx != ry) {
p[rx] = ry;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
if (cin >> n >> q) {
p.resize(n + 1);
for (int i = 0; i <= n; ++i) {
p[i] = i;
}
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
m(l - 1, r);
}
if (f(0) == f(n)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
Amazon Hackathon โ
#include <vector>
using namespace std;
vector<int> p;
int f(int x) {
if (p[x] == x) return x;
return p[x] = f(p[x]);
}
void m(int x, int y) {
int rx = f(x);
int ry = f(y);
if (rx != ry) {
p[rx] = ry;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
if (cin >> n >> q) {
p.resize(n + 1);
for (int i = 0; i <= n; ++i) {
p[i] = i;
}
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
m(l - 1, r);
}
if (f(0) == f(n)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
Amazon Hackathon โ
INFOSYS SP โ
โโโโโโโโโโโโโโโ
๐จ Need Help with Coding Exams, Projects, or Technical Interviews?
๐ฏ Get Expert 1-on-1 Assistance
๐ฉ DM Now โ @codemaster004
โก Live Coding Assessments โก Online Assessments (OA) โก Technical Interviews โก Projects & Assignments โก Hackathons & Coding Challenges
โโโโโโโโโโโโโโโ
๐จ Need Help with Coding Exams, Projects, or Technical Interviews?
๐ฏ Get Expert 1-on-1 Assistance
๐ฉ DM Now โ @codemaster004
โก Live Coding Assessments โก Online Assessments (OA) โก Technical Interviews โก Projects & Assignments โก Hackathons & Coding Challenges
#include <vector>
#include <algorithm>
using namespace std;
bool c(const vector<int>& a, const vector<int>& b) {
return a[0] > b[0];
}
int solve(int n, int t, vector<vector<int>>& d) {
sort(d.begin(), d.end(), c);
long long r = t;
long long ans = 0;
while (r > 0) {
int p = -1;
for (int i = 0; i < n; ++i) {
if (d[i][1] > 0 && r % d[i][0] == 0) {
p = i;
break;
}
}
if (p == -1) return -1;
long long u = min(r / d[p][0], (long long)d[p][1]);
r -= u * d[p][0];
ans += u;
d[p][1] -= u;
}
return ans;
}
Infosys SP โ
๐จ Need Help with Coding?
๐ป Live Coding | Projects | Interviews | OA & Hackathons
๐ฏ Expert Assistance Available
๐ฉ DM: @codemaster004
#include <algorithm>
using namespace std;
bool c(const vector<int>& a, const vector<int>& b) {
return a[0] > b[0];
}
int solve(int n, int t, vector<vector<int>>& d) {
sort(d.begin(), d.end(), c);
long long r = t;
long long ans = 0;
while (r > 0) {
int p = -1;
for (int i = 0; i < n; ++i) {
if (d[i][1] > 0 && r % d[i][0] == 0) {
p = i;
break;
}
}
if (p == -1) return -1;
long long u = min(r / d[p][0], (long long)d[p][1]);
r -= u * d[p][0];
ans += u;
d[p][1] -= u;
}
return ans;
}
Infosys SP โ
๐จ Need Help with Coding?
๐ป Live Coding | Projects | Interviews | OA & Hackathons
๐ฏ Expert Assistance Available
๐ฉ DM: @codemaster004
def maximizePacketSum(packetSizes, k):
n = len(packetSizes)
if k > n:
return -1
d = {}
s = 0
m = -1
for i in range(n):
v = packetSizes[i]
s += v
d[v] = d.get(v, 0) + 1
if i >= k:
o = packetSizes[i - k]
s -= o
d[o] -= 1
if d[o] == 0:
del d[o]
if i >= k - 1:
if len(d) == k:
if s > m:
m = s
return m
IBM โ
____
๐ป Live Coding | Projects | Interviews | OA & Hackathons Help
๐ฉ DM: @codemaster004
n = len(packetSizes)
if k > n:
return -1
d = {}
s = 0
m = -1
for i in range(n):
v = packetSizes[i]
s += v
d[v] = d.get(v, 0) + 1
if i >= k:
o = packetSizes[i - k]
s -= o
d[o] -= 1
if d[o] == 0:
del d[o]
if i >= k - 1:
if len(d) == k:
if s > m:
m = s
return m
IBM โ
____
๐ป Live Coding | Projects | Interviews | OA & Hackathons Help
๐ฉ DM: @codemaster004
import requests
def findSpeedster(marathon, sex):
url = f"https://jsonmock.hackerrank.com/api/marathon?sex={sex}"
best_n = ""
best_s = -1.0
best_st = float('inf')
curr_p = 1
total_p = 1
while curr_p <= total_p:
resp = requests.get(f"{url}&page={curr_p}").json()
if curr_p == 1:
total_p = resp['total_pages']
for r in resp['data']:
if r['marathon_name'] == marathon:
s = float(r['top_speed'])
st = int(r['stops_taken'])
if s > best_s:
best_s = s
best_st = st
best_n = r['name']
elif s == best_s:
if st < best_st:
best_st = st
best_n = r['name']
curr_p += 1
return best_n
IBM โ
_
๐ป Live Coding | Projects | Interviews | OA & Hackathons Help
๐ฉ DM: @codemaster004
def findSpeedster(marathon, sex):
url = f"https://jsonmock.hackerrank.com/api/marathon?sex={sex}"
best_n = ""
best_s = -1.0
best_st = float('inf')
curr_p = 1
total_p = 1
while curr_p <= total_p:
resp = requests.get(f"{url}&page={curr_p}").json()
if curr_p == 1:
total_p = resp['total_pages']
for r in resp['data']:
if r['marathon_name'] == marathon:
s = float(r['top_speed'])
st = int(r['stops_taken'])
if s > best_s:
best_s = s
best_st = st
best_n = r['name']
elif s == best_s:
if st < best_st:
best_st = st
best_n = r['name']
curr_p += 1
return best_n
IBM โ
_
๐ป Live Coding | Projects | Interviews | OA & Hackathons Help
๐ฉ DM: @codemaster004
Wells Fargo โ
๐ป Live Coding Test | Projects | Interviews | OA & Hackathons
๐ฉ DM: @codemaster004
๐ป Live Coding Test | Projects | Interviews | OA & Hackathons
๐ฉ DM: @codemaster004
๐ฅ HCLTech is Hiring! ๐ฅ
๐ป Role:
* Freshers Hiring / Off-Campus Drive
* India
๐ Eligibility:
* Batch: 2026
* Freshers
๐ Key Requirements:
* Good understanding of foundational software engineering concepts
* Strong analytical and communication skills
๐ Click below to apply:
๐ Application Link : https://freshers.hcltech.com/?utm_source=OffCampus&utm_medium=OffCampus_T1Institutions_Batch2026&utm_campaign=OffCampus_T1Institutions_Batch2026&utm_term=HCLTech
๐ป Live Coding Test | Projects | Interviews | OA & Hackathons Help
๐ฉ DM: @codemaster004
๐ป Role:
* Freshers Hiring / Off-Campus Drive
* India
๐ Eligibility:
* Batch: 2026
* Freshers
๐ Key Requirements:
* Good understanding of foundational software engineering concepts
* Strong analytical and communication skills
๐ Click below to apply:
๐ Application Link : https://freshers.hcltech.com/?utm_source=OffCampus&utm_medium=OffCampus_T1Institutions_Batch2026&utm_campaign=OffCampus_T1Institutions_Batch2026&utm_term=HCLTech
๐ป Live Coding Test | Projects | Interviews | OA & Hackathons Help
๐ฉ DM: @codemaster004