FastPrepGenerate Array
Problems/Generate Array

Generate Array

Uber logoUber● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array of words. Build a new array of the same length. Entry i is the first letter of words[i] followed by the last letter of the next word, words[i + 1].

The words are in a circle. The next word after the last word is the first word, words[0]. If there is only one word, its next word is itself.

For example, with ["cat", "dog", "flower", "bed"] the result is ["cg", "dr", "fd", "bt"]. The word "cat" gives c and the last letter of "dog", which is g. The last word "bed" gives b and the last letter of "cat", which is t.

Complete the function generateArray in the editor.

generateArray has the following parameter:

  • String[] words: the words

The function returns a String[]: the new array, with two letters in each entry.

Function

generateArray(words: String[]) → String[]

Examples

Example 1

words = ["cat", "dog", "flower", "bed"]return = ["cg", "dr", "fd", "bt"]

Each entry takes the first letter of a word and the last letter of the next word. "cat" and "dog" give "cg". "dog" and "flower" give "dr". "flower" and "bed" give "fd". The last word "bed" goes back to the first word "cat" and gives "bt".

Constraints

  • 1 ≤ words.length ≤ 105
  • 1 ≤ words[i].length ≤ 100
  • The total length of all words is at most 106.
  • Each word has only lowercase English letters.

More Uber interview questions

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
  • Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
  • Convex Function MinimizationPHONE SCREEN · Seen Oct 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Merge Meeting IntervalsPHONE SCREEN · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Serialize and Deserialize an N-Ary TreeONSITE INTERVIEW · Seen Oct 2026
  • Find Robots by Blocker DistancesPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
  • Customer Signer ScreeningState Farm · OA
  • REST API: Highest International StudentsRippling · OARippling interview questions
  • String-Pair Frequency SimilarityIBM · OAIBM interview questions
  • Find Sliding-Window Pattern Start IndicesVisa · OAVisa interview questions
  • Closest ColorTwo Sigma · OATwo Sigma interview questions
  • Number-Character Bijective MappingAdobe · OAAdobe interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public String[] generateArray(String[] words) {
      // write your code here
    }

}
Checking account…