Posts

Showing posts from October, 2016

Upside-Down Tree - Part 1 of 2

Image
TL;DR A full binary tree is given to you. Your job is to print it upside-down: level by level, but upside-down. There are many methods for doing so, the next post will describe three different methods. Stay tuned!!! And don't be a nasty woman or nasty man!!!

Narcissistic Numbers

The Narcissistic Numbers are just a toy in number theory. They are defined as follows: given a number M = d1d2...dn, M is said to be "Narcissistic" if and only if: d1^n + d2^n + ... + dn^n = M. For example, 153 is a very well-known Narcissistic Number since 1^3 + 5^3 + 3^3 = 153. There is a Numberphile video that talks about this number too. These numbers, unlike many other sequences in Math, are finite: there are only 89 of those numbers, all listed here . In this post I'll consider two other related sequences of numbers, but not as "glamorous" as Narcissistic Numbers. The sequences will be the  Quasi-Narcissistic-Numbers or QNN, and the Retro-Narcissistic-Numbers or RNN. Let's define QNN first. A number M=d1d2...dn is said to be a QNN if and only if: a) It is not a Narcissistic Number b) It follows the same properties as the Narcissistic Numbers except that one, and only one, of the exponents in d1^n + d2^n + ... + dn^n is off by one. Wh...

Two Characters, by HackerRank

Image
A problem posted by HackerRank on the surface might seem tricky - here is it:  https://www.hackerrank.com/challenges/two-characters String   always consists of two distinct alternating characters. For example, if string  's two distinct characters are  x and  y , then  t  could be  xyxyx  or  yxyxy  but  not   xxyy  or  xyyx . You can convert some string   to string   by deleting characters from  . When you delete a character from  , you must delete  all  occurrences of it in  . For example, if    abaacdabd  and you delete the character  a , then the string becomes  bcdbd . Given  , convert it to the longest possible string  . Then print the length of string   on a new line; if no string   can be formed from  , print   instead. There are few aspects to notice that will make this problem...