SDE Intern
3 Questions
Optimal Array Partition Problem Statement You are given an array A of N positive integers. Partition the array into exactly K non empty contiguous subarrays such that the total cost is minimized. The cost of a subarray is defined as: (max element - min element) * length of the subarray The total cost is the sum of costs of all subarrays. Input Format First line: two integers N and K Second line: N space-separated integers A[i] Output Format Print a single integer - the minimum total cost
Problem Statement There are N cities numbered from 1 to N connected by M bidirectional roads. Each road has a travel time. Additionally, there are K magical bridges. Each magical bridge connects two cities and takes zero time to travel, but each bridge can be used at most once. You start from city 1 and want to reach city N using at most K magical bridges. Find the minimum time required. Input Format First line: three integers N, M, K Next M lines: three integers u, v, w representing a road between u and v with travel time w Next K lines: two integers u, v representing a magical bridge Output Format Print a single integer -> the minimum time to reach city N from city 1 If it is not possible, print -1
Problem Statement You are given N tasks that must be assigned to K servers. Each task has a processing load. Tasks must be assigned in contiguous groups. Each group is assigned to one server, and the load on a server is the sum of the loads of tasks assigned to it. Your goal is to minimize the maximum load on any server. Input Format First line: two integers N and K Second line: N space separated integers representing task loads Output Format Print a single integer -> the minimum possible maximum load
Divyansh Garg·Apr 2026