Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Generate Star Patterns and Arrays

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Generate Star Patterns and Arrays. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Ascentt interview utilities may need to format simple visual output and reshape two-dimensional data. Write a function that generates a left-aligned growing star pattern and returns the transpose of a rectangular matrix.

For an integer n, the pattern must contain n strings. The string at position i must contain exactly i + 1 asterisks, with no spaces between them. For a matrix with r rows and c columns, the transposed matrix must have c rows and r columns. Element (i, j) in the original matrix must appear at (j, i) in the result.

Formal Specification

Implement build_pattern_and_transpose(n, matrix).

  • Input: n, a positive integer, and matrix, a non-empty rectangular two-dimensional list of integers.
  • Output: a dictionary with two keys:
    • pattern: a list of strings representing the star pattern.
    • transpose: a two-dimensional list containing the transposed matrix.
  • The input matrix must not be modified.

Constraints

  • 1 <= n <= 100
  • 1 <= len(matrix) <= 100
  • 1 <= len(matrix[0]) <= 100
  • All rows have the same length
  • Matrix values are integers

Function Signature

def build_pattern_and_transpose(n, matrix):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output