top of page

Code Challenge #1

Updated: Nov 10, 2023

You are given an N by M 2D matrix of lowercase letters. Determine the minimum number of columns that can be removed to ensure that each row is ordered from top to bottom lexicographically. That is, the letter at each column is lexicographically later as you go down each row. It does not matter whether each row itself is ordered lexicographically.



For example, given the following table:

​Example 1

cba

daf

ghi

This is not ordered because of the a in the center. We can remove the second column to make it ordered:

Example 2

ca

df

gi

So your function should return 1, since we only needed to remove 1 column. As another example, given the following table:

Example 3

abcdef

Your function should return 0, since the rows are already ordered (there's only one row).

As another example, given the following table:

Example 4

zyx

wvu

tsr


Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Subscribe to get exclusive updates

Thanks for subscribing!

CONTACT ME
avatar-formal-round.png

Follow

  • Medium
  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • Youtube
  • linktree
  • Buy Me A Coffee

© 2019 - 2024 By Biyi Akinpelu. The LORD Is My Banner

bottom of page