FastPrepRecipe Rating Service
Problems/Recipe Rating Service

Recipe Rating Service

Nubank logoNubank● MediumFULLTIMEPHONE SCREEN

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a Nubank phone screen for a full-time software engineering role. The candidate, who has a bachelor's degree and was changing jobs, came in through a recruiter and passed.

From the report: the round was a coding task on an online platform, written from scratch with no classes provided, and looking up syntax was allowed. The candidate found it easy: object-oriented code with a little data structures and sorting. The task was a recipe service built up over three parts: storing recipes and fetching them; ratings from users, with a ban on rating your own recipe; and ranking, both the top k recipes by average rating and the best-rated recipe for a set of ingredients. The thread title calls the round system design, but the task itself was coding.

Everything else is our choice: the input as one list of operations with one result list per operation; the operation names and their fields; recipe ids numbered by creation order, starting at recipe1, with no separate user sign-up; the second fetch operation, a user's own recipes; scores from 1 to 5; returning false for a missing recipe or a self-rating; a repeat rating replacing the earlier one; comparing averages exactly, as fractions; ties going to the recipe created first; leaving unrated recipes out of both rankings; reading a set of ingredients as the recipes whose every ingredient is in the list; the limits; the names runRecipeService and operations; the examples; and the follow-up questions at the end of the editorial.

Our version is about 70% the same as the reported question.

Write a recipe service that keeps all of its data in memory. The input operations holds the commands. Carry them out one after another. The output holds one string list per command, in the same order as the commands.

The first recipe created is called recipe1, the second recipe2, the third recipe3, and the numbering keeps counting up from there. Users are plain ids. There is no separate sign-up step: any user id may create or rate recipes.

Part 1: Create and fetch recipes

  • ["CREATE_RECIPE", authorId, name, ingredientsCsv]: create a recipe written by authorId. ingredientsCsv lists its ingredients, joined by commas. Two recipes may have the same name. The result is [recipeId], the id of the new recipe.
  • ["GET_RECIPE", recipeId]: the result is [name, authorId, ingredientsCsv], with the ingredients exactly as they were given when the recipe was created. If the id matches no recipe, the result is [].
  • ["GET_AUTHOR_RECIPES", authorId]: list the ids of the recipes that authorId wrote, oldest first. An author with no recipes gets [].

Part 2: Rate recipes

  • ["RATE_RECIPE", userId, recipeId, score]: userId gives the recipe a score from 1 to 5. When the id matches no recipe, or when userId wrote the recipe, the result is ["false"] and nothing changes: authors may not rate their own recipes. Otherwise the rating is saved and the result is ["true"]. A user has at most one rating per recipe, so if the user rated this recipe before, the new score replaces the old one.

Part 3: Find the best recipes

The average rating of a recipe is the sum of its current scores divided by the number of users who rated it. Compare averages exactly, as fractions: for example, 9 / 2 is higher than 4, and 4 / 3 ties with 8 / 6. A higher average ranks higher. If two recipes have the same average, the one created earlier, with the smaller number in its id, ranks higher. A recipe with no ratings has no average and is never part of the answer to these two operations.

  • ["TOP_RATED", k]: give the ids of the k highest-ranked rated recipes, best first. If fewer than k recipes have ratings, give all of them, possibly none at all.
  • ["BEST_RECIPE_FOR", ingredientsCsv]: these are the ingredients you have. A recipe can be made if every one of its ingredients is in this list. The list may hold extra ingredients that the recipe never uses. The result is [recipeId] for the highest-ranked rated recipe that can be made. If no rated recipe can be made, the result is [].

Boolean results are always the lowercase strings "true" or "false".

Function

runRecipeService(operations: String[][]) → String[][]

Examples

Example 1

operations = [["CREATE_RECIPE","ana","Pancakes","flour,egg,milk"],["CREATE_RECIPE","ben","Omelette","egg,cheese"],["CREATE_RECIPE","ana","Toast","bread,butter"],["GET_RECIPE","recipe2"],["GET_AUTHOR_RECIPES","ana"],["RATE_RECIPE","ben","recipe1","4"],["RATE_RECIPE","ana","recipe1","5"],["RATE_RECIPE","ana","recipe7","3"],["GET_RECIPE","recipe9"]]return = [["recipe1"],["recipe2"],["recipe3"],["Omelette","ben","egg,cheese"],["recipe1","recipe3"],["true"],["false"],["false"],[]]

The three new recipes are numbered by creation order, recipe1 to recipe3. ana wrote recipe1 and recipe3. ben may rate recipe1, but ana may not rate her own recipe, and nobody can rate recipe7 because it does not exist. Fetching a missing recipe gives an empty list.

Example 2

operations = [["CREATE_RECIPE","ana","Soup","water,salt"],["CREATE_RECIPE","ben","Stew","water,beef"],["CREATE_RECIPE","cal","Rice","rice"],["RATE_RECIPE","ben","recipe1","4"],["RATE_RECIPE","ana","recipe2","5"],["RATE_RECIPE","cal","recipe2","3"],["RATE_RECIPE","cal","recipe1","2"],["RATE_RECIPE","cal","recipe1","4"],["TOP_RATED","2"],["TOP_RATED","5"]]return = [["recipe1"],["recipe2"],["recipe3"],["true"],["true"],["true"],["true"],["true"],["recipe1","recipe2"],["recipe1","recipe2"]]

recipe1 has the scores 4 from ben and 4 from cal: cal first gave 2, and the second rating replaced it. Its average is 8 / 2 = 4. recipe2 has 5 and 3, also an average of 4. The tie goes to the recipe created first, so recipe1 is listed ahead of recipe2. recipe3 has no rating, so it is never listed, and asking for 5 recipes returns only the two rated ones.

Example 3

operations = [["CREATE_RECIPE","ana","Salad","lettuce,tomato"],["CREATE_RECIPE","ben","Sandwich","bread,tomato,ham"],["CREATE_RECIPE","cal","Tomato Toast","bread,tomato"],["CREATE_RECIPE","dee","Plain Bread","bread"],["RATE_RECIPE","ana","recipe2","5"],["RATE_RECIPE","ana","recipe3","4"],["RATE_RECIPE","ben","recipe1","3"],["BEST_RECIPE_FOR","bread,tomato,lettuce"],["BEST_RECIPE_FOR","bread,tomato,ham,cheese"],["BEST_RECIPE_FOR","bread"]]return = [["recipe1"],["recipe2"],["recipe3"],["recipe4"],["true"],["true"],["true"],["recipe3"],["recipe2"],[]]

With bread, tomato and lettuce you can make recipe1 (average 3), recipe3 (average 4) and recipe4, but not recipe2, which also needs ham. recipe4 has no rating, so the best is recipe3. The second list, bread, tomato, ham and cheese, can make recipe2 (average 5), recipe3 and recipe4, so the best is recipe2; the unused cheese does not matter. With only bread, the one recipe you can make has no rating, so the answer is empty.

Constraints

  • 1 <= operations.length <= 1000
  • Each operation takes one of the six forms described above, with the same number of values as that form.
  • Every authorId and userId is 1 to 10 lowercase letters or digits.
  • Every name is 1 to 30 characters: letters, digits and single spaces, with no space at the start or end.
  • Every ingredient is 1 to 15 lowercase letters. An ingredientsCsv is distinct ingredients joined by commas, with no spaces: 1 to 10 of them in CREATE_RECIPE and 1 to 20 in BEST_RECIPE_FOR.
  • Every score is one digit from 1 to 5.
  • Every k is an integer with 1 <= k <= 1000, written without leading zeros.
  • Every recipeId argument is recipe followed by an integer n with 1 <= n < 10^9, written without leading zeros. The recipe it names might never have been created.

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
  • Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Versioned Snapshot SetOpenAI · PHONE SCREENOpenAI interview questions
  • Interview Slot BookingTrueFoundry · PHONE SCREEN
  • Config Store with Priority OverridesMicrosoft · PHONE SCREENMicrosoft interview questions
  • Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • In-Memory Database with TTL and Historical QueriesZip · PHONE SCREENZip interview questions
  • Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
See Nubank hiring insights
Saved
class Solution {
    public String[][] runRecipeService(String[][] operations) {
        // Write your code here.
    }
}
Checking account…