Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pramp-interview1: toeplitz matrix #10

Merged
merged 7 commits into from
May 9, 2020
Merged

Conversation

VeronicaM
Copy link
Owner

@VeronicaM VeronicaM commented May 9, 2020

All PRs

  • I have self-reviewed my code
  • I have written tests which cover new and changed functionality
  • All tests pass
  • I have commented on difficult to understand code

Where Relevant

  • I have compared and validated my UI changes against the designs
  • I've updated relevant documentation e.g. README

Description

What is this PR about ?

An algorithm that checks wether a 2 dimensional array (i.e. a matrix which can be either square or have an unequal number of rows and columns) is of type Toeplitz, i.e. all its descending diagonals have the same value from left to right.

This was part of the question I had to interview my paired interviewer/interviewee on my first time using Pramp

What was implemented ?

  • Use two loops to traverse the columns and the rows, limit loop to columns number - 1 and rows number - 1 as number of diagonals will always equal matrix dimensions - 1
  • Identify the Toepliz matrix condition for descending diagonals as matrix[i][j] !== matrix[i + 1][j + 1]
  • Return false if condition is not met
  • Return true if the two loops finish without finding a case that doesn't match the conditon.

Runtime complexity: O(n^2)
Space complexity: O(1)

What did you learn ?

  • What a Toepliz Matrix is
  • How to find the descending diagonals equation by matching elements values in the matrix with their corresponding i, j ( column, row) indexes.

What links/documents relate to this PR ?

Testing

Steps required to test

  • cd interviews/pramp/toeplitz-matrix
  • run node toeplitz-matrix.js

All tests should pass
Test cases can be found in interviews/pramp/toeplitz-matrix/testData

@VeronicaM VeronicaM merged commit 9e19eec into master May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant