LOOP MASTER
JAVA
import java.util.*;
public class loopMaster {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
List<String> EXAMASSISTANCE = new ArrayList<>();
for (int i = 0; i < n; i++) {
EXAMASSISTANCE.add(sc.nextLine().trim());
}
processCommands(EXAMASSISTANCE);
}
private static void processCommands(List<String> EXAMASSISTANCE) {
Stack<Integer> loopCounts = new Stack<>();
Stack<Integer> currIter = new Stack<>();
StringBuilder output = new StringBuilder();
int index = 0;
while (index < EXAMASSISTANCE.size()) {
String command = EXAMASSISTANCE.get(index);
if (command.startsWith("for")) {
int times = Integer.parseInt(command.split(" ")[1]);
loopCounts.push(times);
currIter.push(0);
} else if (command.equals("do")) {
} else if (command.equals("done")) {
int current = currIter.pop() + 1;
int max = loopCounts.pop();
if (current < max) {
loopCounts.push(max);
currIter.push(current);
index = findLoopStart(EXAMASSISTANCE, index);
continue;
}
} else if (command.startsWith("break")) {
int breakAt = Integer.parseInt(command.split(" ")[1]);
if (currIter.peek() + 1 == breakAt) {
loopCounts.pop();
currIter.pop();
index = findLoopEnd(EXAMASSISTANCE, index);
}
} else if (command.startsWith("continue")) {
int continueAt = Integer.parseInt(command.split(" ")[1]);
if (currIter.peek() + 1 == continueAt) {
int max = loopCounts.peek();
int current = currIter.pop() + 1;
if (current < max) {
currIter.push(current);
index = findLoopStart(EXAMASSISTANCE, index);
}
continue;
}
} else if (command.startsWith("print")) {
String message = command.substring(command.indexOf("\"") + 1, command.lastIndexOf("\""));
output.append(message).append("\n");
}
index++;
}
System.out.print(output.toString());
}
private static int findLoopStart(List<String> EXAMASSISTANCE, int ci) {
int nestedLoops = 0;
for (int i = ci - 1; i >= 0; i--) {
if (EXAMASSISTANCE.get(i).equals("done")) {
nestedLoops++;
} else if (EXAMASSISTANCE.get(i).equals("do")) {
if (nestedLoops == 0) {
return i;
}
nestedLoops--;
}
}
return 0;
}
private static int findLoopEnd(List<String> EXAMASSISTANCE, int ci) {
int nestedLoops = 0;
for (int i = ci + 1; i < EXAMASSISTANCE.size(); i++) {
if (EXAMASSISTANCE.get(i).equals("do")) {
nestedLoops++;
} else if (EXAMASSISTANCE.get(i).equals("done")) {
if (nestedLoops == 0) {
return i;
}
nestedLoops--;
}
}
return EXAMASSISTANCE.size();
}
}
LOOP MASTER CODE
JAVA
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
JAVA
import java.util.*;
public class loopMaster {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
List<String> EXAMASSISTANCE = new ArrayList<>();
for (int i = 0; i < n; i++) {
EXAMASSISTANCE.add(sc.nextLine().trim());
}
processCommands(EXAMASSISTANCE);
}
private static void processCommands(List<String> EXAMASSISTANCE) {
Stack<Integer> loopCounts = new Stack<>();
Stack<Integer> currIter = new Stack<>();
StringBuilder output = new StringBuilder();
int index = 0;
while (index < EXAMASSISTANCE.size()) {
String command = EXAMASSISTANCE.get(index);
if (command.startsWith("for")) {
int times = Integer.parseInt(command.split(" ")[1]);
loopCounts.push(times);
currIter.push(0);
} else if (command.equals("do")) {
} else if (command.equals("done")) {
int current = currIter.pop() + 1;
int max = loopCounts.pop();
if (current < max) {
loopCounts.push(max);
currIter.push(current);
index = findLoopStart(EXAMASSISTANCE, index);
continue;
}
} else if (command.startsWith("break")) {
int breakAt = Integer.parseInt(command.split(" ")[1]);
if (currIter.peek() + 1 == breakAt) {
loopCounts.pop();
currIter.pop();
index = findLoopEnd(EXAMASSISTANCE, index);
}
} else if (command.startsWith("continue")) {
int continueAt = Integer.parseInt(command.split(" ")[1]);
if (currIter.peek() + 1 == continueAt) {
int max = loopCounts.peek();
int current = currIter.pop() + 1;
if (current < max) {
currIter.push(current);
index = findLoopStart(EXAMASSISTANCE, index);
}
continue;
}
} else if (command.startsWith("print")) {
String message = command.substring(command.indexOf("\"") + 1, command.lastIndexOf("\""));
output.append(message).append("\n");
}
index++;
}
System.out.print(output.toString());
}
private static int findLoopStart(List<String> EXAMASSISTANCE, int ci) {
int nestedLoops = 0;
for (int i = ci - 1; i >= 0; i--) {
if (EXAMASSISTANCE.get(i).equals("done")) {
nestedLoops++;
} else if (EXAMASSISTANCE.get(i).equals("do")) {
if (nestedLoops == 0) {
return i;
}
nestedLoops--;
}
}
return 0;
}
private static int findLoopEnd(List<String> EXAMASSISTANCE, int ci) {
int nestedLoops = 0;
for (int i = ci + 1; i < EXAMASSISTANCE.size(); i++) {
if (EXAMASSISTANCE.get(i).equals("do")) {
nestedLoops++;
} else if (EXAMASSISTANCE.get(i).equals("done")) {
if (nestedLoops == 0) {
return i;
}
nestedLoops--;
}
}
return EXAMASSISTANCE.size();
}
}
LOOP MASTER CODE
JAVA
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
TOGGLE CHALLENGE CODE
JAVA
import java.util.*;
public class Toggle{
public static List<Integer> getPossibleDigits(Map<Integer, String> validDigits, String faultyDigit) {
List<Integer> potentialDigits = new ArrayList<>();
for (Map.Entry<Integer, String> entry : validDigits.entrySet()) {
int mismatches = 0;
String pattern = entry.getValue();
for (int i = 0; i < faultyDigit.length(); i++) {
if (faultyDigit.charAt(i) != pattern.charAt(i)) {
mismatches++;
}
}
if (mismatches <= 1) {
potentialDigits.add(entry.getKey());
}
}
return potentialDigits;
}
public static void solve() {
Scanner scanner = new Scanner(System.in);
List<String> segmentDisplay = new ArrayList<>();
for (int i = 0; i < 3; i++) {
segmentDisplay.add(scanner.nextLine().strip());
}
List<String> EXAMASSISTANCE = new ArrayList<>();
for (int i = 0; i < 3; i++) {
EXAMASSISTANCE.add(scanner.nextLine().strip());
}
Map<Integer, String> digitPatterns = new HashMap<>();
for (int digit = 0; digit < 10; digit++) {
StringBuilder pattern = new StringBuilder();
for (int row = 0; row < 3; row++) {
pattern.append(segmentDisplay.get(row).substring(digit * 3, (digit + 1) * 3));
}
digitPatterns.put(digit, pattern.toString());
}
List<List<Integer>> possibleNumbers = new ArrayList<>();
for (int i = 0; i < EXAMASSISTANCE.get(0).length() / 3; i++) {
StringBuilder faultyDigit = new StringBuilder();
for (int row = 0; row < 3; row++) {
faultyDigit.append(EXAMASSISTANCE.get(row).substring(i * 3, (i + 1) * 3));
}
List<Integer> matchingDigits = getPossibleDigits(digitPatterns, faultyDigit.toString());
if (matchingDigits.isEmpty()) {
System.out.print("Invalid");
return;
}
possibleNumbers.add(matchingDigits);
}
int totalSum = 0;
for (List<Integer> combination : getCombinations(possibleNumbers)) {
StringBuilder number = new StringBuilder();
for (int digit : combination) {
number.append(digit);
}
totalSum += Integer.parseInt(number.toString());
}
System.out.print(totalSum);
}
public static List<List<Integer>> getCombinations(List<List<Integer>> possibleNumbers) {
List<List<Integer>> result = new ArrayList<>();
getCombinationsHelper(possibleNumbers, 0, new ArrayList<>(), result);
return result;
}
private static void getCombinationsHelper(List<List<Integer>> possibleNumbers, int index, List<Integer> currentCombination, List<List<Integer>> result) {
if (index == possibleNumbers.size()) {
result.add(new ArrayList<>(currentCombination));
return;
}
for (int digit : possibleNumbers.get(index)) {
currentCombination.add(digit);
getCombinationsHelper(possibleNumbers, index + 1, currentCombination, result);
currentCombination.remove(currentCombination.size() - 1);
}
}
public static void main(String[] args) {
solve();
}
}
TOGGLE CHALLENGE CODE IN
JAVA
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
JAVA
import java.util.*;
public class Toggle{
public static List<Integer> getPossibleDigits(Map<Integer, String> validDigits, String faultyDigit) {
List<Integer> potentialDigits = new ArrayList<>();
for (Map.Entry<Integer, String> entry : validDigits.entrySet()) {
int mismatches = 0;
String pattern = entry.getValue();
for (int i = 0; i < faultyDigit.length(); i++) {
if (faultyDigit.charAt(i) != pattern.charAt(i)) {
mismatches++;
}
}
if (mismatches <= 1) {
potentialDigits.add(entry.getKey());
}
}
return potentialDigits;
}
public static void solve() {
Scanner scanner = new Scanner(System.in);
List<String> segmentDisplay = new ArrayList<>();
for (int i = 0; i < 3; i++) {
segmentDisplay.add(scanner.nextLine().strip());
}
List<String> EXAMASSISTANCE = new ArrayList<>();
for (int i = 0; i < 3; i++) {
EXAMASSISTANCE.add(scanner.nextLine().strip());
}
Map<Integer, String> digitPatterns = new HashMap<>();
for (int digit = 0; digit < 10; digit++) {
StringBuilder pattern = new StringBuilder();
for (int row = 0; row < 3; row++) {
pattern.append(segmentDisplay.get(row).substring(digit * 3, (digit + 1) * 3));
}
digitPatterns.put(digit, pattern.toString());
}
List<List<Integer>> possibleNumbers = new ArrayList<>();
for (int i = 0; i < EXAMASSISTANCE.get(0).length() / 3; i++) {
StringBuilder faultyDigit = new StringBuilder();
for (int row = 0; row < 3; row++) {
faultyDigit.append(EXAMASSISTANCE.get(row).substring(i * 3, (i + 1) * 3));
}
List<Integer> matchingDigits = getPossibleDigits(digitPatterns, faultyDigit.toString());
if (matchingDigits.isEmpty()) {
System.out.print("Invalid");
return;
}
possibleNumbers.add(matchingDigits);
}
int totalSum = 0;
for (List<Integer> combination : getCombinations(possibleNumbers)) {
StringBuilder number = new StringBuilder();
for (int digit : combination) {
number.append(digit);
}
totalSum += Integer.parseInt(number.toString());
}
System.out.print(totalSum);
}
public static List<List<Integer>> getCombinations(List<List<Integer>> possibleNumbers) {
List<List<Integer>> result = new ArrayList<>();
getCombinationsHelper(possibleNumbers, 0, new ArrayList<>(), result);
return result;
}
private static void getCombinationsHelper(List<List<Integer>> possibleNumbers, int index, List<Integer> currentCombination, List<List<Integer>> result) {
if (index == possibleNumbers.size()) {
result.add(new ArrayList<>(currentCombination));
return;
}
for (int digit : possibleNumbers.get(index)) {
currentCombination.add(digit);
getCombinationsHelper(possibleNumbers, index + 1, currentCombination, result);
currentCombination.remove(currentCombination.size() - 1);
}
}
public static void main(String[] args) {
solve();
}
}
TOGGLE CHALLENGE CODE IN
JAVA
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
Plague 2050
PYTHON
from collections import deque
def infected_neighbors_count(grid, a, b):
n = len(grid)
count = 0
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(len(directions)):
dx, dy = directions[i]
nx, ny = a + dx, b + dy
if 0 <= nx < n and 0 <= ny < n and grid[nx][ny] == 1:
count += 1
return count
def infection_process(grid):
n = len(grid)
new_grid = [[grid[i][j] for j in range(n)] for i in range(n)]
for i in range(n):
for j in range(n):
neighbors = infected_neighbors_count(grid, i, j)
if grid[i][j] == 0 and neighbors == 3:
new_grid[i][j] = 1
elif grid[i][j] == 1 and (neighbors < 2 or neighbors > 3):
new_grid[i][j] = 0
return new_grid
def find_path(size, initial_grid):
grid = [[1 if cell == '1' else 0 for cell in row] for row in initial_grid]
start_x, start_y, end_x, end_y = -1, -1, -1, -1
def set_positions():
nonlocal start_x, start_y, end_x, end_y
for i in range(size):
for j in range(size):
if initial_grid[i][j] == 's':
start_x, start_y = i, j
grid[i][j] = 0
if initial_grid[i][j] == 'd':
end_x, end_y = i, j
grid[i][j] = 0
set_positions()
queue = deque([(start_x, start_y, grid, 0)])
seen_states = set()
while queue:
x, y, current_grid, days = queue.popleft()
if (x, y) == (end_x, end_y):
return days
state = (x, y, tuple(map(tuple, current_grid)))
if state in seen_states:
continue
seen_states.add(state)
next_grid = infection_process(current_grid)
moves = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)]
for dx, dy in moves:
nx, ny = x + dx, y + dy
if 0 <= nx < size and 0 <= ny < size and next_grid[nx][ny] == 0:
queue.append((nx, ny, next_grid, days + 1))
return -1
if name == "main":
n = int(input())
pollution_map = [input().strip() for _ in range(n)]
print(find_path(n, pollution_map) + 1)
PLAGUE 2050
Python
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
PYTHON
from collections import deque
def infected_neighbors_count(grid, a, b):
n = len(grid)
count = 0
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(len(directions)):
dx, dy = directions[i]
nx, ny = a + dx, b + dy
if 0 <= nx < n and 0 <= ny < n and grid[nx][ny] == 1:
count += 1
return count
def infection_process(grid):
n = len(grid)
new_grid = [[grid[i][j] for j in range(n)] for i in range(n)]
for i in range(n):
for j in range(n):
neighbors = infected_neighbors_count(grid, i, j)
if grid[i][j] == 0 and neighbors == 3:
new_grid[i][j] = 1
elif grid[i][j] == 1 and (neighbors < 2 or neighbors > 3):
new_grid[i][j] = 0
return new_grid
def find_path(size, initial_grid):
grid = [[1 if cell == '1' else 0 for cell in row] for row in initial_grid]
start_x, start_y, end_x, end_y = -1, -1, -1, -1
def set_positions():
nonlocal start_x, start_y, end_x, end_y
for i in range(size):
for j in range(size):
if initial_grid[i][j] == 's':
start_x, start_y = i, j
grid[i][j] = 0
if initial_grid[i][j] == 'd':
end_x, end_y = i, j
grid[i][j] = 0
set_positions()
queue = deque([(start_x, start_y, grid, 0)])
seen_states = set()
while queue:
x, y, current_grid, days = queue.popleft()
if (x, y) == (end_x, end_y):
return days
state = (x, y, tuple(map(tuple, current_grid)))
if state in seen_states:
continue
seen_states.add(state)
next_grid = infection_process(current_grid)
moves = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)]
for dx, dy in moves:
nx, ny = x + dx, y + dy
if 0 <= nx < size and 0 <= ny < size and next_grid[nx][ny] == 0:
queue.append((nx, ny, next_grid, days + 1))
return -1
if name == "main":
n = int(input())
pollution_map = [input().strip() for _ in range(n)]
print(find_path(n, pollution_map) + 1)
PLAGUE 2050
Python
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
MAXIMUM ROTATION
PYTHON
def rl(layer, pos, dir, ol):
n = len(layer)
rot = [None] * n
if dir == "clockwise":
for i in range(n):
rot[(i + pos) % n] = layer[i]
else:
for i in range(n):
rot[(i - pos) % n] = layer[i]
for i in range(n):
if ol:
rot[i] = chr(((ord(rot[i]) - ord('A') - 1) % 26) + ord('A'))
else:
rot[i] = chr(((ord(rot[i]) - ord('A') + 1) % 26) + ord('A'))
return rot
def aq(pl, row, col, size):
layers = []
for layer in range(size // 2):
cl = []
for j in range(col + layer, col + size - layer):
cl.append(pl[row + layer][j])
for i in range(row + layer + 1, row + size - layer - 1):
cl.append(pl[i][col + size - layer - 1])
for j in range(col + size - layer - 1, col + layer - 1, -1):
cl.append(pl[row + size - layer - 1][j])
for i in range(row + size - layer - 2, row + layer, -1):
cl.append(pl[i][col + layer])
layers.append(cl)
for lidx, layer in enumerate(layers):
ol = (lidx + 1) % 2 == 1
dir = "counterclockwise" if ol else "clockwise"
pos = lidx + 1
rotated_layer = rl(layer, pos, dir, ol)
idx = 0
for j in range(col + lidx, col + size - lidx):
pl[row + lidx][j] = rotated_layer[idx]
idx += 1
for i in range(row + lidx + 1, row + size - lidx - 1):
pl[i][col + size - lidx - 1] = rotated_layer[idx]
idx += 1
for j in range(col + size - lidx - 1, col + lidx - 1, -1):
pl[row + size - lidx - 1][j] = rotated_layer[idx]
idx += 1
for i in range(row + size - lidx - 2, row + lidx, -1):
pl[i][col + lidx] = rotated_layer[idx]
idx += 1
def MAX_ROTATION(n, pl, queries):
for row, col, size in queries:
aq(pl, row, col, size)
result = ''.join(''.join(row) for row in pl)
return result
n = int(input())
pl = [list(input().strip().split()) for _ in range(n)]
q = int(input().strip())
queries = [tuple(map(int, input().strip().split())) for _ in range(q)]
result = MAX_ROTATION(n, pl, queries)
print(result, end="")
MAXIMUM ROTATION
PYTHON
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
PYTHON
def rl(layer, pos, dir, ol):
n = len(layer)
rot = [None] * n
if dir == "clockwise":
for i in range(n):
rot[(i + pos) % n] = layer[i]
else:
for i in range(n):
rot[(i - pos) % n] = layer[i]
for i in range(n):
if ol:
rot[i] = chr(((ord(rot[i]) - ord('A') - 1) % 26) + ord('A'))
else:
rot[i] = chr(((ord(rot[i]) - ord('A') + 1) % 26) + ord('A'))
return rot
def aq(pl, row, col, size):
layers = []
for layer in range(size // 2):
cl = []
for j in range(col + layer, col + size - layer):
cl.append(pl[row + layer][j])
for i in range(row + layer + 1, row + size - layer - 1):
cl.append(pl[i][col + size - layer - 1])
for j in range(col + size - layer - 1, col + layer - 1, -1):
cl.append(pl[row + size - layer - 1][j])
for i in range(row + size - layer - 2, row + layer, -1):
cl.append(pl[i][col + layer])
layers.append(cl)
for lidx, layer in enumerate(layers):
ol = (lidx + 1) % 2 == 1
dir = "counterclockwise" if ol else "clockwise"
pos = lidx + 1
rotated_layer = rl(layer, pos, dir, ol)
idx = 0
for j in range(col + lidx, col + size - lidx):
pl[row + lidx][j] = rotated_layer[idx]
idx += 1
for i in range(row + lidx + 1, row + size - lidx - 1):
pl[i][col + size - lidx - 1] = rotated_layer[idx]
idx += 1
for j in range(col + size - lidx - 1, col + lidx - 1, -1):
pl[row + size - lidx - 1][j] = rotated_layer[idx]
idx += 1
for i in range(row + size - lidx - 2, row + lidx, -1):
pl[i][col + lidx] = rotated_layer[idx]
idx += 1
def MAX_ROTATION(n, pl, queries):
for row, col, size in queries:
aq(pl, row, col, size)
result = ''.join(''.join(row) for row in pl)
return result
n = int(input())
pl = [list(input().strip().split()) for _ in range(n)]
q = int(input().strip())
queries = [tuple(map(int, input().strip().split())) for _ in range(q)]
result = MAX_ROTATION(n, pl, queries)
print(result, end="")
MAXIMUM ROTATION
PYTHON
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
OFFICE ROSTERING
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, k, d = 1, EXAMASSISTANCE = 0;
cin >> n >> m;
vector<set<int>> f(n);
for (int i = 0, u, v; i < m; ++i)
{
cin >> u >> v;
f[u].insert(v);
f[v].insert(u);
}
cin >> k;
vector<bool> w(n, true);
EXAMASSISTANCE = n;
while (EXAMASSISTANCE < k)
{
vector<bool> nw(n, false);
for (int i = 0; i < n; ++i)
{
int cnt = 0;
for (int fr : f[i]) cnt += w[fr];
if (w[i] && cnt == 3) nw[i] = true;
else if (!w[i] && cnt < 3) nw[i] = true;
}
w = nw;
EXAMASSISTANCE += count(w.begin(), w.end(), true);
++d;
}
cout << d;
return 0;
}
OFFICE ROSTERING
C++
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, k, d = 1, EXAMASSISTANCE = 0;
cin >> n >> m;
vector<set<int>> f(n);
for (int i = 0, u, v; i < m; ++i)
{
cin >> u >> v;
f[u].insert(v);
f[v].insert(u);
}
cin >> k;
vector<bool> w(n, true);
EXAMASSISTANCE = n;
while (EXAMASSISTANCE < k)
{
vector<bool> nw(n, false);
for (int i = 0; i < n; ++i)
{
int cnt = 0;
for (int fr : f[i]) cnt += w[fr];
if (w[i] && cnt == 3) nw[i] = true;
else if (!w[i] && cnt < 3) nw[i] = true;
}
w = nw;
EXAMASSISTANCE += count(w.begin(), w.end(), true);
++d;
}
cout << d;
return 0;
}
OFFICE ROSTERING
C++
โ๏ธ โ๏ธ โ๏ธ โ๏ธ
Equation Puzzle Code
C++
TCS CodeVita Season 12 Round 1 Zone 2
int main()
{
string e1, e2;
int r;
cin >> e1 >> e2 >> r;
int a1, b1, c1, d1, n1, a2, b2, c2, d2, n2;
sscanf(e1.c_str(), "%dx+%dy+%dz+%dw<=%d", &a1, &b1, &c1, &d1, &n1);
sscanf(e2.c_str(), "%dx+%dy+%dz+%dw<=%d", &a2, &b2, &c2, &d2, &n2);
vector<vector<int>> combinations;
for (int x = 0; x <= r; x++)
{
for (int y = 0; y + x <= r; y++)
{
for (int z = 0; z + x + y <= r; z++)
{
int w = r - x - y - z;
combinations.push_back({x, y, z, w});
}
}
}
set<int> results;
for (auto &vars1 : combinations)
{
int v1 = a1 * vars1[0] + b1 * vars1[1] + c1 * vars1[2] + d1 * vars1[3];
if (v1 > n1) continue;
for (auto &vars2 : combinations)
{
int v2 = a2 * vars2[0] + b2 * vars2[1] + c2 * vars2[2] + d2 * vars2[3];
if (v2 > n2) continue;
if (v1 == v2) results.insert(v1);
}
}
cout << results.size() << endl;
return 0;
}
Equation Puzzle Code
C++
โ๏ธ โ๏ธ โ๏ธ โ๏ธdef rotate_layer(layer, positions, direction, odd_layer):
n = len(layer)
rotated = [None] * n
if direction == "clockwise":
for i in range(n):
rotated[(i + positions) % n] = layer[i]
else: # counterclockwise
for i in range(n):
rotated[(i - positions) % n] = layer[i]
for i in range(n):
if odd_layer:
rotated[i] = chr(((ord(rotated[i]) - ord('A') - 1) % 26) + ord('A'))
else:
rotated[i] = chr(((ord(rotated[i]) - ord('A') + 1) % 26) + ord('A'))
return rotated
def apply_query(matrix, row, col, size):
layers = []
for layer in range(size // 2):
current_layer = []
for j in range(col + layer, col + size - layer):
current_layer.append(matrix[row + layer][j])
for i in range(row + layer + 1, row + size - layer - 1):
current_layer.append(matrix[i][col + size - layer - 1])
for j in range(col + size - layer - 1, col + layer - 1, -1):
current_layer.append(matrix[row + size - layer - 1][j])
for i in range(row + size - layer - 2, row + layer, -1):
current_layer.append(matrix[i][col + layer])
layers.append(current_layer)
for layer_idx, layer in enumerate(layers):
odd_layer = (layer_idx + 1) % 2 == 1
direction = "counterclockwise" if odd_layer else "clockwise"
positions = layer_idx + 1
rotated_layer = rotate_layer(layer, positions, direction, odd_layer)
idx = 0
for j in range(col + layer_idx, col + size - layer_idx):
matrix[row + layer_idx][j] = rotated_layer[idx]
idx += 1
for i in range(row + layer_idx + 1, row + size - layer_idx - 1):
matrix[i][col + size - layer_idx - 1] = rotated_layer[idx]
idx += 1
for j in range(col + size - layer_idx - 1, col + layer_idx - 1, -1):
matrix[row + size - layer_idx - 1][j] = rotated_layer[idx]
idx += 1
for i in range(row + size - layer_idx - 2, row + layer_idx, -1):
matrix[i][col + layer_idx] = rotated_layer[idx]
idx += 1
def process_matrix(n, matrix, queries):
for row, col, size in queries:
apply_query(matrix, row, col, size)
result = ''.join(''.join(row) for row in matrix)
return result
n = int(input())
matrix = [list(input().strip().split()) for _ in range(n)]
q = int(input().strip())
queries = [tuple(map(int, input().strip().split())) for _ in range(q)]
result = process_matrix(n, matrix, queries)
print(result, end="")
Matrix Rotation
n = len(layer)
rotated = [None] * n
if direction == "clockwise":
for i in range(n):
rotated[(i + positions) % n] = layer[i]
else: # counterclockwise
for i in range(n):
rotated[(i - positions) % n] = layer[i]
for i in range(n):
if odd_layer:
rotated[i] = chr(((ord(rotated[i]) - ord('A') - 1) % 26) + ord('A'))
else:
rotated[i] = chr(((ord(rotated[i]) - ord('A') + 1) % 26) + ord('A'))
return rotated
def apply_query(matrix, row, col, size):
layers = []
for layer in range(size // 2):
current_layer = []
for j in range(col + layer, col + size - layer):
current_layer.append(matrix[row + layer][j])
for i in range(row + layer + 1, row + size - layer - 1):
current_layer.append(matrix[i][col + size - layer - 1])
for j in range(col + size - layer - 1, col + layer - 1, -1):
current_layer.append(matrix[row + size - layer - 1][j])
for i in range(row + size - layer - 2, row + layer, -1):
current_layer.append(matrix[i][col + layer])
layers.append(current_layer)
for layer_idx, layer in enumerate(layers):
odd_layer = (layer_idx + 1) % 2 == 1
direction = "counterclockwise" if odd_layer else "clockwise"
positions = layer_idx + 1
rotated_layer = rotate_layer(layer, positions, direction, odd_layer)
idx = 0
for j in range(col + layer_idx, col + size - layer_idx):
matrix[row + layer_idx][j] = rotated_layer[idx]
idx += 1
for i in range(row + layer_idx + 1, row + size - layer_idx - 1):
matrix[i][col + size - layer_idx - 1] = rotated_layer[idx]
idx += 1
for j in range(col + size - layer_idx - 1, col + layer_idx - 1, -1):
matrix[row + size - layer_idx - 1][j] = rotated_layer[idx]
idx += 1
for i in range(row + size - layer_idx - 2, row + layer_idx, -1):
matrix[i][col + layer_idx] = rotated_layer[idx]
idx += 1
def process_matrix(n, matrix, queries):
for row, col, size in queries:
apply_query(matrix, row, col, size)
result = ''.join(''.join(row) for row in matrix)
return result
n = int(input())
matrix = [list(input().strip().split()) for _ in range(n)]
q = int(input().strip())
queries = [tuple(map(int, input().strip().split())) for _ in range(q)]
result = process_matrix(n, matrix, queries)
print(result, end="")
Matrix Rotation
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐Interactive Brokers is hiring for Junior Software Engineer
Experience: 0 - 1 year
Expected Salary: 9-16 LPA
๐ปApply here: https://job-boards.greenhouse.io/ibkr/jobs/7735288002?Source=Linkedin
Experience: 0 - 1 year
Expected Salary: 9-16 LPA
๐ปApply here: https://job-boards.greenhouse.io/ibkr/jobs/7735288002?Source=Linkedin
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐Phone pay Hiring
Role: Analyst
Qualifications:
- Bachelorโs degree in Data Science, Statistics, Business Analytics, or a related field. A masterโs degree is a plus.
๐ปApply Link: https://boards.greenhouse.io/embed/job_app?token=6268352003
Role: Analyst
Qualifications:
- Bachelorโs degree in Data Science, Statistics, Business Analytics, or a related field. A masterโs degree is a plus.
๐ปApply Link: https://boards.greenhouse.io/embed/job_app?token=6268352003
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int M;
cin >> M;
vector<vector<int>> matrix(M, vector<int>(M));
for (int i = 0; i < M; ++i) {
for (int j = 0; j < M; ++j) {
cin >> matrix[i][j];
}
}
for (int i = 0; i < M; ++i) {
if (i % 2 == 0) {
sort(matrix[i].begin(), matrix[i].end());
} else {
sort(matrix[i].begin(), matrix[i].end(), greater<int>());
}
}
for (int j = 0; j < M; ++j) {
vector<int> column(M);
for (int i = 0; i < M; ++i) {
column[i] = matrix[i][j];
}
if (j % 2 == 0) {
sort(column.begin(), column.end());
} else {
sort(column.begin(), column.end(), greater<int>());
}
for (int i = 0; i < M; ++i) {
matrix[i][j] = column[i];
}
}
for (int i = M - 1; i >= 0; --i) {
for (int j = 0; j < M; ++j) {
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}
BNP โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
vector<int> d(n, 1), c(n, 1);
for (int i = 1; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (p[i] > p[j]) {
if (d[i] < d[j] + 1) {
d[i] = d[j] + 1;
c[i] = c[j];
} else if (d[i] == d[j] + 1) {
c[i] += c[j];
}
}
}
}
int m = *max_element(d.begin(), d.end());
int res = 0;
for (int i = 0; i < n; ++i) {
if (d[i] == m) {
res += c[i];
}
}
cout << res << endl;
return 0;
}
BNP โ
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string solve(string a, string b, int c) {
int d = a.length();
vector<bool> e(c + 1, false);
for (int f = 0; f < d; f++) {
int g = (b[f] - a[f] + 26) % 26;
bool h = false;
for (int i = 1; i <= c; i++) {
if (!e[i] && i == g) {
h = true;
e[i] = true;
break;
}
}
if (!h) {
return "No";
}
}
return "Yes";
}
int main() {
string a, b;
int c;
cin >> a >> b >> c;
cout << solve(a, b, c) << endl;
return 0;
}
MAQ โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Adtran is hiring Software Engineer
For 2021, 2022 gards
Location: Hyderabad
https://adtran.wd3.myworkdayjobs.com/en-US/ADTRAN/job/Software-Engineer_R003741
For 2021, 2022 gards
Location: Hyderabad
https://adtran.wd3.myworkdayjobs.com/en-US/ADTRAN/job/Software-Engineer_R003741
Myworkdayjobs
Software Engineer
Welcome! Our Growth is Creating Great Opportunities! Our team is expanding, and we want to hire the most talented people we can. Continued success depends on it! Once you've had a chance to explore our current open positions, apply to the ones you feel suitโฆ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Linkedin
#hiring #hiringintern #frontend #frontendhiring #intern | Pavan Gandhi | 45 comments
๐ Hiring Frontend Intern! ๐
We at MyWays.ai are looking for a talented Frontend Intern to join us in crafting user-centric experiences for our AI SaaS product, Zeko AI
๐ก Whatโs in it for you?
An opportunity to work with cutting-edge technologies, solveโฆ
We at MyWays.ai are looking for a talented Frontend Intern to join us in crafting user-centric experiences for our AI SaaS product, Zeko AI
๐ก Whatโs in it for you?
An opportunity to work with cutting-edge technologies, solveโฆ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
careers
Junior Associate-Application Development in Gurgaon, Haryana | Careers at SoftwareOne, Gurgaon, India
Why SoftwareOne?
Looking for an internship or first job? Starting your career is complicated, isn't it?
Not with us! You can become a new #swomie and enjoy the advantages we have prepared for new talents, as we want you to gain experience but also developโฆ
Looking for an internship or first job? Starting your career is complicated, isn't it?
Not with us! You can become a new #swomie and enjoy the advantages we have prepared for new talents, as we want you to gain experience but also developโฆ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(const string &s) {
int n = s.length();
vector<vector<int>> adj(n);
vector<int> result(n, 0);
for (int a = 0; a < n; a++) {
if (s[a] == '1') {
int b = 2 * a + 1;
int c = 2 * a + 2;
if (b < n && s[b] == '1')
{
adj[a].push_back(b);
adj[b].push_back(a);
}
if (c < n && s[c] == '1')
{
adj[a].push_back(c);
adj[c].push_back(a);
}
}
}
auto bfs = [&](int start) {
vector<int> dist(n, -1);
queue<int> q;
q.push(start);
dist[start] = 0;
int maxDist = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : adj[u]) {
if (dist[v] == -1) {
dist[v] = dist[u] + 1;
maxDist = max(maxDist, dist[v]);
q.push(v);
}
}
}
return maxDist;
};
for (int a = 0; a < n; a++)
{
if (s[a] == '1')
{
result[a] = bfs(a);
}
}
vector<int> res;
for (int a = 0; a < n; a++)
{
if (s[a] == '1')
{
res.push_back(result[a]);
}
}
return res;
}
int main() {
string s;
cin >> s;
vector<int> res = solve(s);
for (int x : res)
{
cout << x << " ";
}
cout << endl;
return 0;
}
Barclays โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name : Zynga
Batch : 2023/2022/2021
Role : Software Engineer 1
Link : https://job-boards.greenhouse.io/zyngacareers/jobs/5379737004?gh_src=503a64f04us
Batch : 2023/2022/2021
Role : Software Engineer 1
Link : https://job-boards.greenhouse.io/zyngacareers/jobs/5379737004?gh_src=503a64f04us
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Linkedin
Simran Kataria on LinkedIn: ๐ Weโre Hiring! Join Our Team at Enalo Technologies Pvt. Ltd.!๐
We areโฆ | 239 comments
We areโฆ | 239 comments
๐ Weโre Hiring! Join Our Team at Enalo Technologies Pvt. Ltd.!๐
We are looking for a passionate and skilled Backend Developer Intern to join our dynamicโฆ | 239 comments on LinkedIn
We are looking for a passionate and skilled Backend Developer Intern to join our dynamicโฆ | 239 comments on LinkedIn