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

DAA Lab Task-1

The document presents ten problem statements focused on divide and conquer algorithms, including merging sorted linked lists, sorting linked lists, counting set bits in binary representations, searching in a 2D matrix, counting smaller numbers after each element, sorting an array, finding the maximum sum of a circular subarray, generating a beautiful array, identifying the top K frequent elements, and converting a sorted array into a binary search tree. Each problem includes input examples and expected output to illustrate the requirements. The problems are designed to test various algorithmic skills and efficiency.

Uploaded by

231fa04094
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 views5 pages

DAA Lab Task-1

The document presents ten problem statements focused on divide and conquer algorithms, including merging sorted linked lists, sorting linked lists, counting set bits in binary representations, searching in a 2D matrix, counting smaller numbers after each element, sorting an array, finding the maximum sum of a circular subarray, generating a beautiful array, identifying the top K frequent elements, and converting a sorted array into a binary search tree. Each problem includes input examples and expected output to illustrate the requirements. The problems are designed to test various algorithmic skills and efficiency.

Uploaded by

231fa04094
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/ 5

Problems Statements on Divide & Conquer

Problem Statement-1
Merge K Sorted Lists
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
Example:
Input: lists = [[1,4,5], [1,3,4], [2,6]]
Output: [1,1,2,3,4,4,5,6]
Explanation: The linked lists are:
1->4->5,
1->3->4,
2->6
merging them into one sorted list:
1->1->2->3->4->4->5->6
Problem Statement-2
Sort List
Given the head of a linked list, return the list after sorting it in ascending order.
Example:

Input: head = [4,2,1,3]


Output: [1,2,3,4]

Input: head = [-1,5,3,4,0]


Output: [-1,0,3,4,5]
Problem Statement-3
Number of 1 Bits
Given a positive integer n, write a function that returns the number of set bits in its binary
representation (also known as the Hamming weight).
Example 1:
Input: n = 11
Output: 3
Explanation:
The input binary string 1011 has a total of three set bits.
Example 2:
Input: n = 128
Output: 1
Explanation:
The input binary string 10000000 has a total of one set bit.

Problem Statement-4
Search a 2D Matrix
Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix.
This matrix has the following properties:
 Integers in each row are sorted in ascending from left to right.
 Integers in each column are sorted in ascending from top to bottom.
Example:

Input: matrix = [1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]],


target = 5
Output: true
Problem Statement-5
Count of Smaller Numbers After itself
Given an integer array numbers, return an integer array counts where counts[i] is the number
of smaller elements to the right of numbers[i].
Example 1:
Input: numbers = [5,2,6,1]
Output: [2,1,1,0]
Explanation:
To the right of 5 there are 2 smaller elements (2 and 1).
To the right of 2 there is only 1 smaller element (1).
To the right of 6 there is 1 smaller element (1).
To the right of 1 there is 0 smaller element.
Example 2:
Input: numbers = [-1]
Output: [0]

Problem Statement-6
Sort an Array
Given an array of integers numbers, sort the array in ascending order and return it. You must
solve the problem without using any built-in functions in O(nlog(n)) time complexity and
with the smallest space complexity possible.
Example 1:
Input: numbers = [5,2,3,1]
Output: [1,2,3,5]
Explanation: After sorting the array, the positions of some numbers are not changed (for
example, 2 and 3), while the positions of other numbers are changed (for example, 1 and 5).
Example 2:
Input: numbers = [5,1,1,2,0,0]
Output: [0,0,1,1,2,5]
Explanation: Note that the values of numbers are not necessarily unique.
Problem Statement-7
Maximum Sum Circular Subarray
Given a circular integer array numbers of length n, return the maximum possible sum of a
non-empty subarray of numbers.
A circular array means the end of the array connects to the beginning of the array. Formally,
the next element of numbers[i] is numbers[(i + 1) % n] and the previous element of
numbers[i] is numbers[(i - 1 + n) % n].
A subarray may only include each element of the fixed buffer numbers at most once.
Formally, for a subarray numbers[i], numbers[i + 1], ..., numbers[j], there does not exist i <=
k1, k2 <= j with k1 % n == k2 % n.
Example 1:
Input: numbers = [1,-2,3,-2]
Output: 3
Explanation: Subarray [3] has maximum sum 3.
Example 2:
Input: numbers = [5,-3,5]
Output: 10
Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.

Problem Statement-8
Beautiful Array
An array numbers of length n is beautiful if:
 numbers is a permutation of the integers in the range [1, n].
 For every 0 <= i < j < n, there is no index k with i < k < j where 2 * nums[k] ==
nums[i] + nums[j].
Given the integer n, return any beautiful array nums of length n. There will be at least one
valid answer for the given n.

Example 1:

Input: n = 4
Output: [2,1,4,3]
Example 2:
Input: n = 5
Output: [3,1,2,5,4]
Problem Statement-9
Top K Frequent Elements
Given an integer array nums and an integer k, return the k most frequent elements. You may
return the answer in any order.
Example 1:
Input: nums = [1,1,1,2,2,3], k = 2
Output: [1,2]
Example 2:
Input: nums = [1], k = 1
Output: [1]

Problem Statement-10
Convert Sorted Array to Binary Search Tree
Given an integer array of numbers where the elements are sorted in ascending order, convert
it to a height-balanced binary search tree.
Example:

Input: nums = [-10,-3,0,5,9]


Output: [0,-3,9,-10,null,5]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy