1. Find Duplicate Files in a Directory
Given a directory path, write a function to find all the files within that directory that have identical contents. The function signature is: List
- > getDuplicates(String filepath) {}. The response[i] should be a list of filenames that have at least two files with identical contents, omitting files that do not have duplicates.
2. Minesweeper Game Data Structure and Optimization
Handwrite the data structure for a Minesweeper game and output the interface the user sees after one click. Discuss how to optimize runtime, especially in cases where there are very few mines. Propose starting DFS from each mine and recording the state of each cell (number of surrounding mines) instead of starting from the click position. Also, suggest optimizing the algorithm for very large minefields by dividing the grid into blocks and performing DFS in the current block, moving to the next block when crossing boundaries.
3. Vehicle Collision Simulation System Design
Design a simple simulation system that can predict when the first collision will occur given several vehicles' speeds, angular velocities, and initial positions, assuming they are moving at a constant velocity. The vehicles' shapes are unknown, but the interviewer asks how to calculate this most easily (with circular shapes). After providing the correct answer, discuss how to design an industrial-level system and code that incorporates object-oriented programming and threading knowledge. Additionally, explain how to solve the problem when the vehicles have different shapes, focusing on system design rather than mathematical formulas.
4. Point Coordinates Extraction on a 2D Plane
Given a 2D plane with points (continuous, non-integer), you are required to find out the coordinates of all the points. A helper function if_exist(min_x, min_y, width, length) is provided, which returns true or false indicating whether there is at least one point in the specified area. Initially, it may seem that the points are integers, but after clarification, it is confirmed that the space is continuous. The solution involves setting an error rate and using binary search to locate the points.
5. Implement a Minesweeper Game
Write a Minesweeper game. The game should be initialized with a grid of cells, some of which contain mines. The player's task is to reveal all cells without mines. When a cell without a mine is revealed, it should display the number of neighboring cells containing mines. The game ends when the player reveals all non-mine cells or a mine is revealed.