[Programming Problem] Verifying an Alien Dictionary

In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this alien language.

[Problem Link]

  • Create a custom comparator which will compare two words based on the order. The custom comparator basically loops through character by character to check order. Do account for cases where one word is smaller than the other or both words are same length.
  • Compare adjacent words in the array using the comparator. If any of them out of place, return false;
 * @param {string[]} words
 * @param {string} order
 * @return {boolean}
var isAlienSorted = function(words, order) {
    const orderMap = {};
    for (var i = 0; i < order.length; i++) orderMap[order[i]] = i;
    for (var i = 0 ; i < words.length-1 ; i++ ) {
        if (compare(words[i], words[i+1], orderMap) === 1) return false;
    return true;    
var compare = function(a, b, orderMap) {
    for ( var i = 0 ; i < Math.min(a.length, b.length) ; i++ ) {
        if (orderMap[a[i]] < orderMap[b[i]]) return -1;
        else if (orderMap[a[i]] > orderMap[b[i]]) return 1;
    if (a.length === b.length) return 0;
    return a.length < b.length ? -1 : 1;

2,893 thoughts on “[Programming Problem] Verifying an Alien Dictionary

  1. The tips presented listed below are simple and easy to add to you, so stay away from justifications and don’t permit them to affect your use of
    this data. Whenever you take the time to use natural
    Thor Love and Thunder, you are going to sense peace of mind begin to make changes today as
    a way to take pleasure in the reward the future.

  2. I’m gone to say to my little brother, that he should also pay a quick visit
    this weblog on regular basis to get updated from hottest gossip.

  3. Opt for the correct flea treatments to your puppy. Some of them
    contain chemical compounds that can raise the chance of cancers in children, and therefore are 1,000 periods as powerful as the secure levels
    recommended with the EPA. Speak with a vet about safe alternatives and keep little kids away when using any flea remedy.

  4. Закажите генеральную уборку на сайте или в группе VK.
    Наш работник приедет в удобное для вас время и рассчитает стоимость работы и сроки в зависимости от объема и площади.
    Наши уборщики используют специализированное оборудование и моющие, чистящие, химические средства от известных брендов, тем самым позволяя выполнить качественные услуги по уборке дома в короткие сроки.
    Опыт работы более 20 лет. Качество обслуживания 100%. Скидки и акции.
    Мытье РѕРєРѕРЅ, СѓР±РѕСЂРєР° офисов, химчистка РјСЏРіРєРѕР№ мебели. Заказать СѓР±РѕСЂРєСѓ коттеджей или генеральную СѓР±РѕСЂРєСѓ квартир, СѓР±РѕСЂРєСѓ после ремонта, мытье РѕРєРѕРЅ Рё фасадов можно РїРѕ телефону – РІСЃРµ услуги РІ нашей клининговой компании это гарантия чистоты!
    глобал клининг

  5. One cardinal rule of food safety that’s as true on a picnic as it is
    in your kitchen is that uncooked food and cooked food must never come in touch with every one other.

    How can you keep your kitchen protected and arranged? Liquids can float away as nicely, so
    drinks like espresso, orange juice, apple cider and tea are packaged
    as powders. Deer like corn, certainly one
    of the most popular food plot choices, however they need different nutrients.
    The element of surprise is the most important part of starting a
    food combat, so it is advisable to make the primary move
    a memorable one you could relish whereas your nemesis tries to piece together what just
    happened. In case you plan to cook picnic foods at residence and keep them hot till ready to eat at your picnic site, you may need
    to keep them heated to not less than 140°F. For the novice cook,
    finding the precise tools to do this may be tough.

  6. Having read this I believed it was very informative. I appreciate you
    spending some time and energy to put this information together.
    I once again find myself spending a significant amount of
    time both reading and leaving comments. But so what,
    it was still worth it!

  7. Pırlanta kolye yaş aralığı fark etmeksizin, hangi yaşta olunursa olunsun kadınlar için en şık ve zarif takılar arasında yer almaya devam ediyor.
    Firmamızın sağladığı sertifikalı pırlanta hizmetimiz sayesinde güvenilir
    ürünlere sahip olabilirsiniz. Günümüzde oldukça
    fazla tercih edilen tek taş kolyelerin de üretimini en kaliteli
    şekilde gerçekleştiriyoruz.

  8. Change them to cash before purchasing or cusine, for traveler’s investigations.
    Although traveler’s inspections are broadly recognized, they are not that easy to use.
    You might get simple-changed by using them, thus it pays being intelligent about it and grab the exact foreign currency prior to using them.

  9. Ask your youngster which kind of Medieval update they really want.
    You could sense that you can guess depending on what you
    understand them, nevertheless they may want something totally new.
    Before you purchase Medieval they won’t play with, consult with your youngster.

  10. I don’t know if it’s just me or if everybody else experiencing problems with your site.
    It appears as if some of the text on your content
    are running off the screen. Can somebody else please provide feedback and let me
    know if this is happening to them as well? This could be a issue with my browser because I’ve
    had this happen before. Appreciate it

  11. The classic reels and feature games are numerous, but if you’re a highroller and looking for something special, we have it for you: the casino proffers plenteousness of considerate bonuses and competitions with day-after-day booking clerk premiums and complimentary spins.

  12. Producing audio could be a great After Ever Happy review. You just need
    to decide which tool appeals to you most. You can then do your training using a close friend.
    Alternatively, you can just use books and video clips to assist direct you.

    Start sluggish and develop your abilities till you can.

    1. https://uec.asia/
      We provide re-engineering services for parts and spare parts, as well as filtration systems, water purification equipment, gaskets, seals, and other equipment for the oil and gas, chemical, and energy industries. Our approach to working with clients always incorporates our expertise and technical efficiency.

    2. https://uec.asia/
      Our company specializes in providing re-engineering services for parts and spare parts, filtration systems, water purification systems, gaskets, seals, and equipment for various industries including oil and gas, chemical, and energy. We are committed to delivering top-quality solutions that combine our expertise and technical efficiency to meet the unique needs of our clients.

  13. The bull rider that completed the best within the event aggregate gained
    the Super Obligation Truck. A bull rider who gained two or extra events turned eligible for to win the $1 million bonus and had
    to win the 2005 PBR BFTS Finals event. Lordy Tugade
    – a part of the 2005-06 Fiesta Convention champion crew the place he
    was awarded the Finals MVP. The Finn was the fastest driver
    of all by way of sectors one and two however lost out in the ultimate a part of the lap.
    However Perez’s superior final-ditch run through
    the primary part of the lap meant he took the FP3 bragging rights on a 1m45.047s to steer the way in which by
    a tenth over Sainz. Verstappen made fast work of the cars forward, sweeping into P3 by Lap 8 with
    solely Perez and Sainz to beat. Carlos Sainz took pole position for the Belgian Grand Prix at Spa-Francorchamps, the
    14th spherical of the 2022 F1 World Championship, despite
    Red Bull’s Max Verstappen setting the quickest time in qualifying.
    Despite that, the Dutchman went prime along with his first
    flying lap, a time of 1m 43.665s placing him six-tenths ahead of Sainz in P2.

  14. If these are the sorts of games you play, it would make
    sense to go for one thing with a lower refresh fee, say 120Hz.
    However, if you’re into esports titles, you’re
    in for an actual deal with here. It scored 149 FPS within the
    1080p/Very High check, which was solely a bit decrease than the opposite RTX3080 Ti-geared up machines.
    In our intensive Metro Exodus benchmark, the Aorus came in a bit behind the pack,
    but not by much, exhibiting that the slightly weaker GPU nonetheless
    can still put up a fight. As you may see within the
    graph above, the Gigabyte scores about the same as other laptops with Core
    i7 12th-gen processors. At first look, the pricey, highly effective new Gigabyte Aorus 17 is
    a little bit of an odd chicken. Sadly, your different charging choice is a
    chunky proper-angle DC barrel plug, which protrudes quite a bit on the best hand aspect.
    Its massive display screen is a bit dim and the port
    layout’s a little bit of a mess, however on the whole the Aorus 17 is
    a aggressive laptop computer that shines when it comes to gaming.

  15. Awesome website you have here but I was curious if you knew
    of any user discussion forums that cover the same topics discussed here?
    I’d really like to be a part of community where
    I can get advice from other experienced individuals that share the same interest.

    If you have any recommendations, please let me know.
    Many thanks!

  16. Although exotic diyas are readily obtainable for sale at the moment of the yr,
    one of the favourite activities right now of the 12
    months, for each kids in addition to adults is diya
    decorating. In India, lantern making or another type of Diwali decoration is considered one of the main craft actions for children presently
    of the yr. A actually eye-catching decoration. At this time of
    the yr it is auspicious for folks to buy new
    furniture or rugs for the home. Once this is finished upgrading the furniture
    or enhancing the look of the home with accessories will make it brighter and extra lovely.

    Much like a new Year’s Eve practice of welcoming good
    luck to a clear dwelling, Diwali perception is inviting the goddess
    to one’s dwelling and wealth will higher enter an orderly house.

    Diwali has key pieces that you may adorn your home with, certainly one of which is the garland of flowers or what is known as
    the Torans.