更多资源与服务
想要了解更多编程面试技巧,或者需要专业的面试辅导、OA代做、简历润色等服务?我们提供全方位的求职面试支持,帮助您在大厂面试真题、系统设计面试和算法面试中脱颖而出,轻松拿到心仪的 offer!无论您是留学生、刚踏入职场的新人,还是需要代码优化建议的开发者,我们的团队由ACM奖牌得主、大厂资深 TLM 及经验丰富的行业老兵组成,确保为您提供最专业的指导。
扫描下方二维码,添加我们的微信,获取更多服务:
关键词:
- 面试代面
- 代码代写
- OA代做
- 面试技巧
- 面试经验分享
- 职业规划
- 编程练习
让我们帮助您在技术面试中脱颖而出,实现职业上的飞跃!
Question 1: Minimum Cost to Adjust Pixel Intensities
Keywords: image processing, dynamic programming, matrix manipulation
Problem Statement:
A grid-like representation of an image is divided into n
rows and m
columns, with each cell containing pixel intensity values. The aim is to improve the visibility of specific objects in the image.
The goal is to adjust the intensity of each pixel to ensure that no pixel in the previous rows (within the same column) has a higher or equal intensity than the given pixel. Each increase in pixel intensity has a cost of one unit per unit of increase.
Solution Approach:
- Greedy Approach: Traverse the matrix from top to bottom. For each row, ensure that the pixel intensity is strictly greater than the pixel in the row above (in the same column). If the condition is not met, increase the pixel intensity, and add the cost of this increase.
- Cost Calculation: Keep track of the total cost as we adjust the intensities to meet the requirements.
Sample Code:
def getMinimumCost(pixelIntensity):
n = len(pixelIntensity)
m = len(pixelIntensity[0])
total_cost = 0
for col in range(m):
for row in range(1, n):
if pixelIntensity[row][col] <= pixelIntensity[row - 1][col]:
increment = pixelIntensity[row - 1][col] - pixelIntensity[row][col] + 1
total_cost += increment
pixelIntensity[row][col] += increment
return total_cost
# Example usage:
pixelIntensity = [
[2, 4, 6],
[4, 2, 7],
[6, 4, 7]
]
print(getMinimumCost(pixelIntensity)) # Output: 6
Question 2: SQL Grade Assignment
Keywords: SQL, query, conditional logic
Problem Statement:
You are given a table named students
that contains the total marks of students in a class. The teacher wants to assign grades to the students based on the following criteria:
- Marks > 90 -> Grade A+
- Marks > 70 -> Grade A
- Marks > 50 -> Grade B
- Marks >= 40 -> Grade C
- Marks < 40 -> Fail
Write an SQL query to return the ID, name, marks, and grade for each student.
Sample SQL Query:
SELECT
id,
name,
marks,
CASE
WHEN marks > 90 THEN 'A+'
WHEN marks > 70 THEN 'A'
WHEN marks > 50 THEN 'B'
WHEN marks >= 40 THEN 'C'
ELSE 'Fail'
END AS grade
FROM students;