Citadel计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(64)
OOD(1)
Algorithm(52)
System Design(7)
高频题(0)
Math(1)
全部(64)
OOD(1)
Algorithm(52)
System Design(7)
高频题(0)
Math(1)
1.visiting cities
2.Count Subarrays with Sum Divisible by K
3.Lexicographical Numbers Ordering
4.Generating n-bit Gray Code Sequence
5.Shortest Subarray with Sum at Least K
6.Count Subarrays with Sum Divisible by K
7.Minimize Score After Adding or Subtracting K from Elements
8.Maximum Length of Turbulent Subarray
9.Count Subarrays with Sum Divisible by K
10.背包问题变种
11.Max num of chocolate
12.并查集问题
13.Even or odd
14.Longest subarray
15.Max Profit with At Most Two Stock Transactions
16.Valid Parentheses String Checker
17.Implement strStr() Function in String
18.Rearrange String to Avoid Adjacent Repeating Characters
19.Maximum Subarray
20.Special Nodes in a Tree
21.Minimum Knight Moves on a Chess Board
22.Process Execution Optimization
23.Maximum Sum Path in a Tree
24.Strong Team Formation
25.Cache Definition and LFU Implementation
26.Building a Strong Hacker Team
27.Special Nodes in a Tree
28.Maximum Value Sum of Non-Empty Paths
29.First Lady of Software Algorithm
30.Tree Path Finding Problem
31.Dynamic Programming Problem
32.Integer Decomposition into Summands
33.Front-end Credit Card Form Component
34.Building a Strong Hacker Team
35.Find the Smallest Positive Integer Not in Array
36.Minimum Unreachable Vertices in a Directed Graph
37.Longest Common Substring with Character Operations
38.Optimized Fibonacci Sequence Calculation
39.Fibonacci Sequence with O(logN) Complexity
40.Implement Monte Carlo Method to Estimate Pi
41.Optimization Problem to Minimize Sum
42.Implement a Circular Queue using an Array
43.Hacker Team Problem using Dynamic Programming
44.Knight's Tour in Chess using BFS
45.Expected Steps to Exit a Grid
46.Variant of LeetCode Problem 23
47.Maximum of an Array with Minimum Comparisons
48.Numerical Analysis Challenge
49.Optimized Matrix Search
50.Median of a 2D Point Set
51.Sliding Windows Problem
52.Cache and CPU Related Concepts
53.Implementing a HashMap
54.Optimal Assignment Problem
55.Design a TinyURL System
56.Design a Message Queue
57.Code Review and Bug Identification
58.Analyze Code Output
59.Design a Key-Value Store
60.Implement str() Function
61.Optimal Road Transformation in Warehouse Network
62.Design a High Performance Logger
63.Special Nodes
64.Number of Moves
1. visiting cities

输入red,blue分别为长度为n的int arr,以及bluecost
red和blue为i-1城到城的距离,bluecost为红线转蓝线的距离,蓝转红无距离。
输出0号红站到1.2...n城的最短距离
例子:red=[5,5,5],blue=[3,3,3],bluecost=3,那么输出[0,5,9,12]
解释:0到0是0,0到1最近的是直接红线=5,0到2是转蓝(3+3)到1城,继续走蓝到2城(+3)
总共=9,0到3是3+3+3+3=12
2. Count Subarrays with Sum Divisible by K
Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.

A subarray is a contiguous part of an array.

 

Example 1:

Input: nums = [4,5,0,-2,-3,1], k = 5
Output: 7
Explanation: There are 7 subarrays with a sum divisible by k = 5:
[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]

Example 2:

Input: nums = [5], k = 9
Output: 0

 

Constraints:

  • 1 <= nums.length <= 3 * 104
  • -104 <= nums[i] <= 104
  • 2 <= k <= 104
3. Lexicographical Numbers Ordering
Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

You must write an algorithm that runs in O(n) time and uses O(1) extra space. 

 

Example 1:

Input: n = 13
Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]

Example 2:

Input: n = 2
Output: [1,2]

 

Constraints:

  • 1 <= n <= 5 * 104
4. Generating n-bit Gray Code Sequence
An n-bit gray code sequence is a sequence of 2n integers where:

  • Every integer is in the inclusive range [0, 2n - 1],
  • The first integer is 0,
  • An integer appears no more than once in the sequence,
  • The binary representation of every pair of adjacent integers differs by exactly one bit, and
  • The binary representation of the first and last integers differs by exactly one bit.
Given an integer n, return any valid n-bit gray code sequence.

 

Example 1:

Input: n = 2
Output: [0,1,3,2]
Explanation:
The binary representation of [0,1,3,2] is [00,01,11,10].
- 00 and 01 differ by one bit
- 01 and 11 differ by one bit
- 11 and 10 differ by one bit
- 10 and 00 differ by one bit
[0,2,3,1] is also a valid gray code sequence, whose binary representation is [00,10,11,01].
- 00 and 10 differ by one bit
- 10 and 11 differ by one bit
- 11 and 01 differ by one bit
- 01 and 00 differ by one bit

Example 2:

Input: n = 1
Output: [0,1]

 

Constraints:

  • 1 <= n <= 16
5. Shortest Subarray with Sum at Least K
Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return -1.

A subarray is a contiguous part of an array.

 

Example 1:

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

Example 2:

Input: nums = [1,2], k = 4
Output: -1

Example 3:

Input: nums = [2,-1,2], k = 3
Output: 3

 

Constraints:

  • 1 <= nums.length <= 105
  • -105 <= nums[i] <= 105
  • 1 <= k <= 109