<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KVGHS6G" height="0" width="0" style="display:none;visibility:hidden"></iframe>

IBM计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(74)
OOD(1)
Algorithm(50)
System Design(13)
高频题(0)
Math(1)
全部(74)
OOD(1)
Algorithm(50)
System Design(13)
高频题(0)
Math(1)
1.Valid subsequence
2.Backspace String Compare
3.Gas Station Circular Route Problem
4.Most Visited Sectors in a Circular Track
5.Design and Implement a Searchable Word Dictionary Data Structure
6.Maximal Square in Binary Matrix
7.Frequency Interval Matching
8.Pair Comparison Count in Two Arrays
9.Find Complete Prefixes
10.Academic Decathlon Team Selection
11.Get the Largest Number by Swapping Digits
12.Find the Maximum Team Size
13.Onsite Coding Assessment
14.Online Coding Assessment
15.CSS Layout for a Form
16.Chess Tournament Winner Determination
17.String Subsequence Problem
18.Classic Stack Problem
19.Minimum CPU Cores for Process Scheduling
20.Lexicographically Smallest String Transformation
21.Balance Parentheses in a String
22.LRU Cache Implementation
23.Database and Distributed Systems
24.Object-Oriented Programming Concepts
25.Understanding of Kubernetes and Jenkins
26.Docker Usage in Projects
27.Maximum Index Reachable with Avoidance
28.Convert Integers to Roman Numerals
29.Minimum Flips to Match Target Binary String
30.Convert Integers to Roman Numerals
31.Minimum Flips to Match Target Binary String
32.String Compression
33.Good Array Calculation
34.CSS Layout for Form
35.Good Array Algorithm
36.Minimum Flips to Match Target String
37.MaxMin Product Calculation
38.Video Game Level Up System
39.Flip Digit to Convert Binary String
40.CSS Flexbox Layout Implementation
41.Sum of Values from i to j and Back to k
42.File Writing and Test Case Issue
43.Sum of Integers from i to j and Back to k
44.Convert Number to Roman Numerals
45.Minimum Flips to Reach Target String
46.GoodArray Product Calculation
47.Finding Factors of an Integer
48.Optimization of Brute Force Solution
49.Sequence Sum Calculation
50.File Sorting and Output
51.Minimum Segments for Player 1 to Win
52.Maximum Length of Substring With Cost Constraint
53.Maximum Substring Change Cost
54.3 Sum Problem
55.Find the K Most Recent Requests
56.CSS Styling for HTML
57.Compare Two JSON Objects
58.Retrieve and Sort Television Shows Information
59.Parse URL and JSON
60.Return a Vector of Non-Repeating Integers of Size K
61.Find Index Pairs with Bitwise XOR Greater Than Bitwise AND
62.String Manipulation and Validation
63.Responsive Web Page Design
64.Validate URL Requests
65.Restaurant Filtering Based on Ratings and Votes
66.HTTP Request Validation and Parameter Parsing
67.Optimize Brute Force Solution for Problem Involving Sums Divisible by D
68.Maximum Binary Number by Bitwise XOR Operations
69.Calculate the Actual Running Time of Tasks
70.Regular Expression Matching for HTTPS URL
71.Tools Proficiency Inquiry
72.Convert an integer array to a list of integers
73.JavaScript Coding Exercise Preparation
74.Minimum Moves to Reach Target Median
1. Valid subsequence
给两个strings A和B,都只由英文字母组成,判断B是否是A的subsequence,也就是能不能在A里面删掉0个或若干个字符得到B。用Two pointers O(n)解决
 
Follow-up:如果有很多个B,要对同一个A做判断,该怎么优化?
2. Backspace String Compare
Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character.

Note that after backspacing an empty text, the text will continue empty.

 

Example 1:

Input: s = "ab#c", t = "ad#c"
Output: true
Explanation: Both s and t become "ac".

Example 2:

Input: s = "ab##", t = "c#d#"
Output: true
Explanation: Both s and t become "".

Example 3:

Input: s = "a#c", t = "b"
Output: false
Explanation: s becomes "c" while t becomes "b".

 

Constraints:

  • 1 <= s.length, t.length <= 200
  • s and t only contain lowercase letters and '#' characters.
 

Follow up: Can you solve it in O(n) time and O(1) space?

3. Gas Station Circular Route Problem
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].

You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.

Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1. If there exists a solution, it is guaranteed to be unique

 

Example 1:

Input: gas = [1,2,3,4,5], cost = [3,4,5,1,2]
Output: 3
Explanation:
Start at station 3 (index 3) and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 4. Your tank = 4 - 1 + 5 = 8
Travel to station 0. Your tank = 8 - 2 + 1 = 7
Travel to station 1. Your tank = 7 - 3 + 2 = 6
Travel to station 2. Your tank = 6 - 4 + 3 = 5
Travel to station 3. The cost is 5. Your gas is just enough to travel back to station 3.
Therefore, return 3 as the starting index.

Example 2:

Input: gas = [2,3,4], cost = [3,4,3]
Output: -1
Explanation:
You can't start at station 0 or 1, as there is not enough gas to travel to the next station.
Let's start at station 2 and fill up with 4 unit of gas. Your tank = 0 + 4 = 4
Travel to station 0. Your tank = 4 - 3 + 2 = 3
Travel to station 1. Your tank = 3 - 3 + 3 = 3
You cannot travel back to station 2, as it requires 4 unit of gas but you only have 3.
Therefore, you can't travel around the circuit once no matter where you start.

 

Constraints:

  • n == gas.length == cost.length
  • 1 <= n <= 105
  • 0 <= gas[i], cost[i] <= 104
4. Most Visited Sectors in a Circular Track
Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]

Return an array of the most visited sectors sorted in ascending order.

Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).

 

Example 1:

Input: n = 4, rounds = [1,3,1,2]
Output: [1,2]
Explanation: The marathon starts at sector 1. The order of the visited sectors is as follows:
1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)
We can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.
Example 2:

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

Example 3:

Input: n = 7, rounds = [1,3,5,7]
Output: [1,2,3,4,5,6,7]

 

Constraints:

  • 2 <= n <= 100
  • 1 <= m <= 100
  • rounds.length == m + 1
  • 1 <= rounds[i] <= n
  • rounds[i] != rounds[i + 1] for 0 <= i < m
5. Design and Implement a Searchable Word Dictionary Data Structure
Design a data structure that supports adding new words and finding if a string matches any previously added string.

Implement the WordDictionary class:

  • WordDictionary() Initializes the object.
  • void addWord(word) Adds word to the data structure, it can be matched later.
  • bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter.
 

Example:

Input
["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
Output
[null,null,null,null,false,true,true,true]

Explanation
WordDictionary wordDictionary = new WordDictionary();
wordDictionary.addWord("bad");
wordDictionary.addWord("dad");
wordDictionary.addWord("mad");
wordDictionary.search("pad"); // return False
wordDictionary.search("bad"); // return True
wordDictionary.search(".ad"); // return True
wordDictionary.search("b.."); // return True

 

Constraints:

  • 1 <= word.length <= 25
  • word in addWord consists of lowercase English letters.
  • word in search consist of '.' or lowercase English letters.
  • There will be at most 3 dots in word for search queries.
  • At most 104 calls will be made to addWord and search.