FastPrepPhoto Album Insert Order
Problems/Photo Album Insert Order

Photo Album Insert Order

C3.ai logoC3.ai● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Three C3.ai new grad online assessment reports from 2020 to 2022 list a photo album task. One of them links an older public thread as the exact task, and a commenter on another C3.ai post matches it to the common problem of building an array by inserting each value at a given index. The reports give no statement of their own.

Here, each photo is inserted at its given position in the album as it stands, and the photos after it shift right. The linked thread mentions up to 2 * 10^5 photos. This version allows up to 3000 so the answers stay small, which means a direct insert is fast enough. The editorial also shows a faster method. Distinct photo IDs and the other limits are our choice.

Our version is about 80% the same as the reported questions.

You are putting photos into an album one at a time, in the order they are given. Photo i has the ID photoIds[i]. When it is added, it goes to position positions[i] of the album as the album is at that moment. Positions start at 0.

The photo that was at that position, and every photo after it, moves one place to the right. If positions[i] equals the number of photos already in the album, the new photo goes at the end.

Return the photo IDs in album order after all photos have been added.

Function

buildAlbum(positions: int[], photoIds: int[]) → int[]

Examples

Example 1

positions = [0,1,1,0]photoIds = [10,20,30,40]return = [40,10,30,20]

The album grows like this: [10], then [10, 20]. Photo 30 goes to position 1, pushing 20 right: [10, 30, 20]. Photo 40 goes to position 0, pushing everything right: [40, 10, 30, 20].

Example 2

positions = [0,0,0]photoIds = [7,8,9]return = [9,8,7]

Every photo goes to the front, so each new photo pushes the earlier ones back. The album ends in reverse order: [9, 8, 7].

Example 3

positions = [0,0,2,1,3]photoIds = [3,6,9,12,15]return = [6,12,3,15,9]

Step by step: [3], [6, 3], [6, 3, 9] (position 2 is the end), [6, 12, 3, 9], and finally [6, 12, 3, 15, 9].

Constraints

  • 1 <= photoIds.length <= 3000
  • positions.length == photoIds.length
  • 0 <= positions[i] <= i
  • 0 <= photoIds[i] <= 10^9
  • All values in photoIds are different.

More C3.ai interview questions

  • Drop Recent Duplicate MessagesOA · Seen Oct 2026
  • Maximum K-Star SumOA · Seen Oct 2026
  • Largest Square Sub-Grid Within a Sum LimitOA · Seen Jan 2023
  • Prefix Scores With the Running MaximumOA · Seen Jan 2023
  • Tree Node With Maximum BeautyOA · Seen Nov 2022
  • Count Vowel Strings With Follow RulesOA · Seen Apr 2022
  • Sort by Frequency, Then ValueOA · Seen Apr 2022
  • Count Distinct Binary Search TreesOA · Seen Mar 2022
  • Count Palindromic Subsequences of Length KOA · Seen Mar 2022
  • Fewest Turns to Open a Wheel LockPHONE SCREEN · Seen Nov 2024

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Book Reading EveningsGoogle · OAGoogle interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
  • Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
  • Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Recursively Expanded Shell Command CountsHudson River Trading · OAHudson River Trading interview questions
  • Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
  • First Value Below Both NeighborsCapital One · OACapital One interview questions
  • REST API: Highest International StudentsRippling · OARippling interview questions

Interview reports that mention this question

  • C3.ai FDE and Other New Grad Roles: 5 Experiences (Part 2 of 2)
  • C3.ai New Grad Interviews: 25 Experiences (Part 1 of 2)

C3.ai interview experiences

  • C3.ai New Grad Forward Deployed Engineer Interview: 1 Experience
All C3.ai interview questionsSee C3.ai hiring insights
Saved
class Solution {
    public int[] buildAlbum(int[] positions, int[] photoIds) {
        // Write your code here.
    }
}
Checking account…