To the Top
File:  root - text - article - 2019 - 12 - word-ordering-in-a-different-alphabetical-order.txt.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 189 Views, 16975 Search Bots | 107 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Apple:

Given a list of words, and an arbitrary alphabetical order, verify that the words are in order of the alphabetical order.

Example:
Input:

words = ["abcd", "efgh"], order="zyxwvutsrqponmlkjihgfedcba"


Output: False
Explanation: 'e' comes before 'a' so 'efgh' should come before 'abcd'

Example 2:
Input:

words = ["zyx", "zyxw", "zyxwy"],
order="zyxwvutsrqponmlkjihgfedcba"


Output: True
Explanation: The words are in increasing alphabetical order

Here's a starting point:


def isSorted(words, order):
# Fill this in.

print isSorted(["abcd", "efgh"], "zyxwvutsrqponmlkjihgfedcba")
# False
print isSorted(["zyx", "zyxw", "zyxwy"],
"zyxwvutsrqponmlkjihgfedcba")
# True
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 189 Views, 16975 Search Bots | 107 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Longest Substring With K Distinct Characters
  2. Daily Interview Puzzle: Ways to Traverse a Grid
  3. Consecutive Ones
  4. Daily Interview Problem: Trapping Rainwater
  5. Daily Interview Problem: Room scheduling
  6. 56 Bytes
  7. [Daily Problem] Remove Consecutive Nodes that Sum to 0
  8. Daily Interview Problem: Word Ordering in a Different Alphabetical Order
  9. Daily Interview Puzzle: Falling Dominoes
  10. Algorithm Interview: Make the Largest Number

Comments (0)

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">