0% found this document useful (0 votes)
7 views

More Advanced Programming Questions

00
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)
7 views

More Advanced Programming Questions

00
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/ 3

Advanced Programming Question Set

Question 1: Number of Islands

Given a 2D grid map of '1's (land) and '0's (water), count the number of islands. An island is

surrounded by water and is formed by connecting adjacent lands horizontally or vertically.

Example:

Input: grid = [['1','1','0','0','0'],['1','1','0','0','0'],['0','0','1','0','0'],['0','0','0','1','1']]

Output: 3

Question 2: Subarray Sum Equals K

Given an array of integers nums and an integer k, find the total number of continuous subarrays

whose sum equals to k.

Example:

Input: nums = [1,1,1], k = 2

Output: 2

Question 3: Maximum Subarray

Given an integer array nums, find the contiguous subarray (containing at least one number) which

has the largest sum and return its sum.

Example:

Input: nums = [-2,1,-3,4,-1,2,1,-5,4]

Output: 6 (from subarray [4,-1,2,1])

Question 4: Sort Colors

Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of

the same color are adjacent, with the colors in the order red, white, and blue. (Use integers 0, 1, and

2 to represent red, white, and blue).

Example:
Input: nums = [2,0,2,1,1,0]

Output: [0,0,1,1,2,2]

Question 5: Group Anagrams

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

Example:

Input: strs = ['eat','tea','tan','ate','nat','bat']

Output: [['eat','tea','ate'],['tan','nat'],['bat']]

Question 6: Spiral Matrix

Given an m x n matrix, return all elements of the matrix in spiral order.

Example:

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

Output: [1,2,3,6,9,8,7,4,5]

Question 7: Longest Increasing Subsequence

Given an integer array nums, return the length of the longest strictly increasing subsequence.

Example:

Input: nums = [10,9,2,5,3,7,101,18]

Output: 4 (The longest increasing subsequence is [2,3,7,101])

Question 8: Climbing Stairs

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2

steps. Find how many distinct ways you can climb to the top.

Example:

Input: n = 3

Output: 3 (ways: [1,1,1], [1,2], [2,1])

Question 9: Find the Duplicate Number


Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive),

find the duplicate number.

Example:

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

Output: 2

Question 10: Course Schedule

There are numCourses courses you have to take, labeled from 0 to numCourses - 1. Some courses

have prerequisites. Given prerequisites as an array of pairs, determine if you can finish all courses.

Example:

Input: numCourses = 2, prerequisites = [[1,0]]

Output: true (you can take course 0 first, then course 1)

You might also like