Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views6 pages

Coding Task (14-9-2024)

The document presents a series of coding assessment problems, each requiring the implementation of algorithms to solve specific challenges. Examples include finding the maximum subarray sum, minimum path sum in a grid, checking for scrambled strings, and determining the number of unique binary search trees. Additional problems involve string interleaving, palindrome partitioning, and calculating the longest increasing path in a matrix, among others.

Uploaded by

Prudhvi Kakani
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)
16 views6 pages

Coding Task (14-9-2024)

The document presents a series of coding assessment problems, each requiring the implementation of algorithms to solve specific challenges. Examples include finding the maximum subarray sum, minimum path sum in a grid, checking for scrambled strings, and determining the number of unique binary search trees. Additional problems involve string interleaving, palindrome partitioning, and calculating the longest increasing path in a matrix, among others.

Uploaded by

Prudhvi Kakani
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
You are on page 1/ 6

CODING ASSESSMENT

1) Maximum Subarray
Given an integer array nums, find the subarray with the largest sum, and return its sum.
Example:
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: The subarray [4,-1,2,1] has the largest sum 6.

2) Minimum Path Sum:


Given a m x n grid filled with non-negative numbers, find a path from top left to bottom
right, which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
Example:

Example-1:
Input: grid = [[1,3,1],[1,5,1],[4,2,1]]
Output: 7
Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
Example-2:
Input: grid = [[1,2,3], [4,5,6]]
Output: 12
3) Scramble String
We can scramble a string s to get a string t using the following algorithm:
1. If the length of the string is 1, stop.
2. If the length of the string is > 1, do the following:
 Split the string into two non-empty substrings at a random index, i.e., if the
string is s, divide it to x and y where s = x + y.
 Randomly decide to swap the two substrings or to keep them in the same
order. i.e., after this step, s may become s = x + y or s = y + x.
 Apply step 1 recursively on each of the two substrings x and y.
Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string of s1,
otherwise, return false.
Example 1:
Input: s1 = "great", s2 = "rgeat"
Output: true
Example 2:
Input: s1 = "abcde", s2 = "caebd"
Output: false

4) Unique Binary Search Trees


Given an integer n, return the number of structurally unique BST's (binary search trees)
which has exactly n nodes of unique values from 1 to n.
Example:

Input: n = 3
Output: 5
5) Interleaving String
Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2.
An interleaving of two strings s and t is a configuration where s and t are divided
into n and m substrings respectively, such that:
 s = s1 + s2 + ... + sn
 t = t1 + t2 + ... + tm
 |n - m| <= 1
 The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ...
Note: a + b is the concatenation of strings a and b.
Example:

Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"


Output: true
Explanation: One way to obtain s3 is:
Split s1 into s1 = "aa" + "bc" + "c", and s2 into s2 = "dbbc" + "a".
Interleaving the two splits, we get "aa" + "dbbc" + "bc" + "a" + "c" = "aadbbcbcac".
Since s3 can be obtained by interleaving s1 and s2, we return true

6) Palindrome Partitioning-1
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
Example:
Input: s = "aab"
Output: [["a","a","b"],["aa","b"]]
7) Palindrome Partitioning-2
Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
Example:
Input: s = "aab"
Output: 1
Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.

8) Maximum Product Subarray


Given an integer array nums, find a subarray that has the largest product, and return the
product.
The test cases are generated so that the answer will fit in a 32-bit integer.
Example:
Input: nums = [2,3,-2,4]
Output: 6
Explanation: [2,3] has the largest product 6.

9) Maximal Square
Given an m x n binary matrix filled with 0's and 1's, find the largest square containing
only 1's and return its area.

Input:
matrix=
[["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
Output: 4
10) Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers
less than or equal to n.
Example 1:
Input: n = 13
Output: 6
Example 2:
Input: n = 0
Output: 0

11) Perfect Squares


Given an integer n, return the least number of perfect square numbers that sum to n.
A perfect square is an integer that is the square of an integer; in other words, it is the product
of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are
not.
Input: n = 12
Output: 3
Explanation: 12 = 4 + 4 + 4.

12) Longest Increasing Path in a Matrix


Given an m x n integers matrix, return the length of the longest increasing path in matrix.
From each cell, you can either move in four directions: left, right, up, or down. You may
not move diagonally or move outside the boundary (i.e., wrap-around is not allowed).

Input: matrix = [[9,9,4],[6,6,8],[2,1,1]]


Output: 4
Explanation: The longest increasing path is [1, 2, 6, 9].
13) Largest Divisible Subset
Given a set of distinct positive integers nums, return the largest subset answer such that every
pair (answer[i], answer[j]) of elements in this subset satisfies:
 answer[i] % answer[j] == 0, or
 answer[j] % answer[i] == 0
If there are multiple solutions, return any of them.
Input: nums = [1,2,3]
Output: [1,2]
Explanation: [1,3] is also accepted.

14) Split Array Largest Sum


Given an integer array nums and an integer k, split nums into k non-empty subarrays such
that the largest sum of any subarray is minimized.
Return the minimized largest sum of the split.
A subarray is a contiguous part of the array.
Example:
Input: nums = [7,2,5,10,8], k = 2
Output: 18
Explanation: There are four ways to split nums into two subarrays.
The best way is to split it into [7,2,5] and [10,8], where the largest sum among the two
subarrays is only 18.

15) Partition Equal Subset Sum


Given an integer array nums, return true if you can partition the array into two subsets such
that the sum of the elements in both subsets is equal or false otherwise.
Example-1:
Input: nums = [1,5,11,5]
Output: true
Explanation: The array can be partitioned as [1, 5, 5] and [11].
Example-2:
Input: nums = [1,2,3,5]
Output: false

You might also like