Ai Software Engineer Interview Questions

231 ai software engineer interview questions shared by candidates

You are working on a backend system that retrieves data from a database. The database has two tables: users and posts. Each user can have many posts, and each post belongs to a user. You are notified that the system is experiencing a performance drop in production, and you isolate the issue to the following snippet: async function getUsersWithPostCountAndEarliestPostDate() { const users = await db.query('SELECT u.id AS user_id, u.name AS user_name FROM users'); for (let user of users) { const posts = await db.query('SELECT * FROM posts WHERE user_id = ?', [user.id]); user.post_count = posts.length; user.earliest_post_date = posts.reduce((earliest, post) => post.created_at < earliest ? post.created_at : earliest, Infinity); if (user.earliest_post_date === Infinity) { user.earliest_post_date = null; } } return users; } What type of problem does this code have? How do we fix it?
avatar

AI First Software Engineer II

Interviewed at Crossover for Work

4.1
Jun 12, 2024

You are working on a backend system that retrieves data from a database. The database has two tables: users and posts. Each user can have many posts, and each post belongs to a user. You are notified that the system is experiencing a performance drop in production, and you isolate the issue to the following snippet: async function getUsersWithPostCountAndEarliestPostDate() { const users = await db.query('SELECT u.id AS user_id, u.name AS user_name FROM users'); for (let user of users) { const posts = await db.query('SELECT * FROM posts WHERE user_id = ?', [user.id]); user.post_count = posts.length; user.earliest_post_date = posts.reduce((earliest, post) => post.created_at < earliest ? post.created_at : earliest, Infinity); if (user.earliest_post_date === Infinity) { user.earliest_post_date = null; } } return users; } What type of problem does this code have? How do we fix it?

Viewing 31 - 40 interview questions

Glassdoor has 231 interview questions and reports from Ai software engineer interviews. Prepare for your interview. Get hired. Love your job.