Visa计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(72)
OOD(4)
Algorithm(51)
System Design(11)
高频题(0)
Math(1)
全部(72)
OOD(4)
Algorithm(51)
System Design(11)
高频题(0)
Math(1)
1.Maximum Path Sum in Binary Tree
2.ThreeSum Problem
3.Alternative Solution to a Problem
4.Minimum Number of Sprinklers to Water a Garden
5.String Compression Algorithm
6.Find the minimum length of the roof that covers K cars
7.Merge Sorted Arrays
8.Design a Coffee Machine
9.Spring Framework Principles
10.Garbage Collection Mechanism
11.Java Collection Framework
12.Coding Task Completion
13.Improving a Given Situation
14.Choosing Data Structures for Specific Scenarios
15.Implementing a Python Dictionary
16.Linux Command for Content Search
17.Linux Command for File Search
18.House Painting Cost Problem
19.Design a Global Sensor System
20.Median of Two Sorted Arrays on Different Machines
21.Detecting Duplicates in an Integer Stream
22.Office Matrix Shortest Distance to Water Cooler
23.File System Traversal
24.HTML/JS Interaction
25.Basic Java Function Implementation
26.Java OOD Principles
27.Count of Anagrams in Sentences Based on Symmetric Word Relationships
28.Minimum Sum of Numbers to Reach Multiple of 2 or 3
29.Sentence Permutations with Anagrams
30.Array Element Division
31.Find the minimum length of the roof that covers K cars
32.Search a 2D Sorted Matrix
33.Intersection of Two Linked Lists
34.Meteor Collision
35.Music Playlist Shuffle
36.System Design for Instagram
37.Dynamic Programming Problem for Substring Matching
38.Prime Number Identification in a Range
39.Coding Problems
40.Fit Packs into Containers
41.String Character Mapping Validation
42.Alice and Bob's Stone Game
43.Bubble Popping Game Debugging
44.Match Songs and Subtitles
45.Coding Problem Solving
46.Distributed System Design
47.Project Deep Dive
48.Smart Sale
49.Budget Shopping
50.Simple Max Difference
51.Sort Strings by the Difference in Total Vowels and Consonants
52.Count Subsequences Matching a Pattern in a String
53.Brightest Point from Street Lamps
54.Bird Nest Building
55.String Reformatting Based on Position
56.Stock Simulation for Maximum Profit
57.Simulate WeChat Message Formatting
58.Count Pairs with Single Digit Difference
59.Segment Tree Allocation and Erasure
60.Waiting Time for Next Bus
61.Design a Six-Digit Password System and Security Code Generator
62.Data Structures and Algorithms Assessment
63.Common Path Suffix
64.2D Tetris-Like Shape Placement
65.Vowel Shifting in a String
66.Odd-Even Sequence Validation
67.Frequency of Black Cells in 2x2 Submatrices
68.Matrix Obstacle Removal for Figures
69.Linux Command Execution Count
70.Keyboard Switch Count
71.Array Pair Swap Count
72.Time Machine Minute Calculation
1. Maximum Path Sum in Binary Tree
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.

The path sum of a path is the sum of the node's values in the path.

Given the root of a binary tree, return the maximum path sum of any non-empty path.

 

Example 1:

Input: root = [1,2,3]
Output: 6
Explanation: The optimal path is 2 -> 1 -> 3 with a path sum of 2 + 1 + 3 = 6.

Example 2:

Input: root = [-10,9,20,null,null,15,7]
Output: 42
Explanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 = 42.

 

Constraints:

  • The number of nodes in the tree is in the range [1, 3 * 104].
  • -1000 <= Node.val <= 1000
2. ThreeSum Problem
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

 

Example 1:

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation: 
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.

Example 2:

Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.

Example 3:

Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.

 

Constraints:

  • 3 <= nums.length <= 3000
  • -105 <= nums[i] <= 105
3. Alternative Solution to a Problem
In the fourth round of an onsite interview, after presenting your initial solution to a problem, you are asked if there is a more straightforward (possibly less efficient) way to solve it, prompting you to write a brute force solution.
4. Minimum Number of Sprinklers to Water a Garden
Given an array representing a garden, where the value at each index represents the range of the sprinkler at that position, determine the minimum number of sprinklers that need to be turned on to water the entire garden. The garden is represented as a 1 to N array, and the range of each sprinkler is given by the array values. Describe a greedy algorithm to solve this problem and discuss its efficiency.
5. String Compression Algorithm
Design an algorithm to compress a given string by describing the total number of consecutive occurrences of each character next to it. For example, the string 'abaasass' should be compressed to 'aba2sas2'. If a character occurs only once, it is added to the compressed string. If it occurs consecutive times, the character is followed by an integer representing the number of consecutive occurrences. Implement the function compressedString that returns the compressed form of a message.