Monday, September 26, 2016

Hanker Rank: order of word

Given a string, find the lexical sequence:
import math
def num(word):
    length=len(word)
    ans=math.factorial(length)
    wordset=set(word)
    for letter in wordset:
        fre=word.count(letter)
        ans=ans/fre
    return ans
def  get_ranks( words):
    if len(words)==1:
        return 0
    setwords=set(words)
    listwords=list(setwords)
    listwords.sort()
    prenumber=0
    head=words[0]
    seq=listwords.index(head)
    for i in range(seq):
        absent=listwords[i]
        k=words.index(absent)
        prenumber+=num(words[0:k]+words[k+1:])

    return prenumber+get_ranks(words[1:])

Friday, September 23, 2016

Subjective well-being

Subjective well-being (SWB) refers to how people experience the quality of their lives and includes both emotional reactions and cognitive judgments. Psychologists have defined happiness as a combination of life satisfaction and the relative frequency of positive and negative experience of feeling.
  • The study of SWB is a central concern of positive psychology.
  • Wealth. At first, SWB increases with income, but has diminishing marginal utility.
  • DNA. SWB is influenced by a combination of personality/genetics (50%), external circumstances (temporary effect) and mental/physical activities (more lasting improvement).
  • Health. SWB is highly correlated to health, which will provide positive feedback to health.
  • “The most salient characteristics shared by the 10% of students with the highest levels of happiness and the fewest signs of depression were their strong ties to friends and family and commitment to spending time with them.” (‘Very Happy People,” Psychological Science 2002)
  • Science of Happiness: Communicating, volunteer and caring, exercise, getting in the flow, spiritual engagement, strengths and virtues, positive thinking (gratitude, savoring and optimism)

Interesting websites for happiness:

why it doesn’t pay to be a people-pleaser

Live with total integrity. Be transparent, honest, and authentic. Do not ever waiver from this; white lies and false smiles quickly snowball into a life lived out of alignment. It is better to be yourself and risk having people not like you than to suffer the stress and tension that comes from pretending to be someone you’re not, or professing to like something that you don’t. I promise you: Pretending will rob you of joy.
  1. We don’t actually fool anyone
    We humans aren’t actually very good at hiding how we are feeling. We exhibit micro-expressions that the people we are with might not know they are registering but that trigger mirror neurons—so a little part of their brain thinks that they are feeling our negative feelings. So trying to suppress negative emotions when we are talking with someone—like when we don’t want to trouble someone else with our own distress—actually increases stress levels of both people more than if we had shared our distress in the first place.(It also reduces rapport and inhibits the connection between two people.)
  2. We find it harder to focus
    Pretending takes a huge conscious effort—it’s an act of self-control that drains your brain of its power to focus and do deep work. That’s because performing or pretending to be or feel something you’re not requires tremendous willpower.
    Tons of research suggests that our ability to repeatedly exert our self-control is actually quite limited. Like a muscle that tires and can no longer perform at its peak strength after a workout, our self-control is diminished by previous efforts at control, even if those efforts take place in a totally different realm.
So that little fib at the water cooler you told in order to make yourself seem happier than you are is going to make it hard for you to focus later in the afternoon. A performance or any attempt to hide who you really are, or pretend to be something you aren’t, is going to make it harder later to control your attention and your thoughts, and to regulate your emotions. It’ll increase the odds that you react more aggressively to a provocation, eat more tempting snacks, engage in riskier behaviors, and—this one is pretty compelling to me—perform more poorly on tasks that require executive function, like managing your time, planning, or organizing
  1. You’ll become more stressed and anxious
    Let’s just call it like it is: Pretending to be or feel something that you don’t—even if it is a small thing, and even if it is relatively meaningless, and even if it is meant to protect someone else—is a lie.
And lying, even if we do it a lot, or are good at it, is very stressful to our brains and our bodies. The polygraph test depends on this: “Lie Detectors” don’t actually detect lies, but rather they detect the subconscious stress and fear that lying causes. These tests sense changes in our skin electricity, pulse rate, and breathing. They also detect when someone’s vocal pitch has changed in a nearly imperceptible way, a consequence of tension in the body that tightens vocal chords.
We don’t lie or pretend or perform all the time, of course. But when we do, it’s important to see the consequences: increased stress, decreased willpower, impaired relationships. Although we might actually be trying to feel better by putting on a happy face for others, pretending always backfires in the end. Living in authentically makes life hard and cuts us off from our sweet spot—that place where we have both ease and power.

Thursday, September 22, 2016

Maslow's motivation theory

Maslow’s need hierarchy theory, original proposed in 1943, is the most popular theory of motivation in the management and Organizational Behavior literature. He studied the healthiest 1% of the college student population, because “the study of crippled, stunted, immature, and unhealthy specimens can yield only a cripple psychology and a cripple philosophy”.

The five levels of need are:

  1. physiological needs
    air, water, food, clothing and shelter
  2. safety needs
    personal security, finacial security, health and well-being
    safety net against accidents/illness/aftermath
  3. love and belonging
    friendship, intimacy, family
    it may override safety need as witnessed in abusive family
    a sense of belonging and acceptance among social groups, like clubs, co-workers, religious groups, professional groups
4, self-esteem/self-respect
be accepted and valued by others, gain recognition
low self-esteem: seek status, attention, fame or glory, need respect from others, but these won’t help build self-esteem until they accept themselves internally
high self-esteem: seek for strength, competence,mastery, self-confidence, independence, and freedom
  1. self-actualization/self-transcendence
    accomplish everything he can, e.g.: painting, inventions
    become the most he can be, e.g.: ideal parent
    giving himself to some higher goal beyond oneself, part of “a greater good”

Comments:

  • M. A. Wahba and L. G. Bridwell (1976): little evidence for the ranking of needs. They can be equally important, depending on age, culture, society development/ stability.
  • sex is listed in 1, which neglects the emotional, famillial, and evolutionary implication
  • 1-3 are defiency needs, 4-5 are growths needs
  • a deprivation may establish a dominance within his hierarchy of needs; conversely, a gratification of need will activate.
  • A long deprivation of a given need may turn him to other needs
  • some proposed dual-level hierarchy: maintenace needs(1-2),growth needs(3-5)
Carl Rogers, who advocated client-centered therapy and student-centered learning, said,
Every human being, with no exception, for the mere fact to be it, is worthy of unconditional respect of everybody else; he deserves to esteem himself and to be esteemed

Wednesday, September 21, 2016

A failed phone interview

On the second day of my previous post, I kind of rushed into a phone interview by G. I didn’t do a good job because I wasted quite a bunch of time on the format of inputs. I should better communicate with the interviewer.
Question: given 2 rectangles, output the intersection rectangle.
def getIntersection(r1,r2):
    '''
    :type r1:list[float]
    :type r2:list[float]
    # only need 2 x-coordiantes and 2 y-coordinates to represent a rectangle. e.g.[x1,x2,y1,y2] #re max,min of x; max,min of y
    :rtype list[float]
    '''
    if r1[0]<=r2[1] or r1[1]>=r2[0] or\
        r1[2]<=r2[3] or r1[3]>=r2[2]:
        return []
    listx=r1[0:2]+r2[0:2]
    ans_x=[x for x in listx if x<max(listx) and x>min(listx)]
    listy=r1[2:]+r2[2:]
    ans_y=[x for x in listy if x<max(listy) and x>min(listy)]
    return ans_x+ans_y

Thursday, September 8, 2016

Technical Interview

This course proivdes resources need to pull off the trick: data structures or a common pattern in the problem. Not every little details like the laws of physics, not at the level of mathematician.
In a real technical interview, you just need to show that you can successfully perform the trick and that you understand the concepts behind it.

outline

  1. Introduction and Efficiency
    Course Introduction
    Syntax
    Efficiency
    run time, storage space
    rely on you creativity and ability
    Notation of Efficiency
    big O notation
    worst case scenario ; upper bound
  2. List-Based Collections
    Lists
    append(), insert(),remove(elem), sort(), reverse() # these command don’t return new list
    pop(index)
    Arrays
    Linked Lists
    Stacks
    Queues
  3. Searching and Sorting
    Binary Search
    Recursion
    Bubble Sort
    n^2
    memory: O(1), in-position
    Merge Sort
    n log(n)
    Quick Sort
    worst case: O(n^2)
    average case: nlog(n)
  4. Maps and Hashing
    Maps
    Hashing
    Collisions
    Hashing Conventions
  5. Trees
    Trees
    Tree Traversal
    Binary Trees
    Binary Search Trees
    Heaps
    Self-Balancing Trees
  6. Graphs
    Graphs
    Graph Properties
    Graph Representation
    Graph Traversal
    Graph Paths
  7. Case Studies in Algorithms
    Shortest Path Problem
    greedy algorithm
    Knapsack Problem
    brute force solution, 2^n
    Traveling Salesman Problem
    NP hard.
    Not always have efficient solution
  8. Technical Interview Tips
    Mock Interview Breakdown
    1 clarifying the question
    prove to interviewer that you won’t dive head first into a probelm and potentially waste time writing code that doesn’t solve the initial issue.
    2 generating inputs and output
    3 generating test cases
    handle weird input
    4 brainstorming
    the interviewer is there to help you and being able to take in their feedback demonstartes your teamwork skills
    5 runtime analysis
    coding
    debugging
    Additional Tips
    Practice with Pramp
    Next Steps

Data Types

boolean = True
number = 1.1
string = "Strings can be declared with single or double quotes."
list = ["Lists can have", 1, 2, 3, 4, "or more types together!"]
tuple = ("Tuples", "can have", "more than", 2, "elements!")
dictionary = {'one': 1, 'two': 2, 'three': 3}
variable_with_zero_data = None

Conditionals

if cake == "delicious":
    return "Yes please!"
elif cake == "okay":
    return "I'll have a small piece."
else:
    return "No, thank you."

Classes

class Person(object): # inherit from object
    def __init__(self, name, age):
        self.name = name
        self.age = age 

    def birthday(self):
        self.age += 1

Friday, September 2, 2016

Product Design, how to start-up

Start ups are risky and costly business, it’s always wise to validate early on, build only what you need, and not more. And iterate as fast as you can.

Yunha Kim

  • After all, it’s not like you can choose whether to be a female CEO vs male CEO. But you can choose your attitude toward it.
  • I tend to be very aggressive. When I want to get things done, I’ll get them done. I tend to be impatient. But it helps me get stuff done.
  • We get gratification from seeing or building stuff in our hand.
  • This one idea that I have needs to be exectued perfectly and you succeed, otherwise a failure.
  • It’s my idea, my dream, I need to make it happen. If you consider as like, these are some of the ideas that we’ll try, if they fail, that’s okay, we’ll move on. At the end of the day, the worst thing happened to us is that we failed and we don’t know exactly why we fail.
  • knowing exactly why I failed is one of the learning that will help us go to the next.
  • The worst thing is to fail slowly and painfully over years.
  • failure is not the opposite of success, it’s a stepping stone to success.
  • learning and failing quickly, and never making the same mistake twice.
  • We fail? But screw your courage to the sticking post, and we’ll not fail.

Idea types

  • Simplify
  • Me too
  • Virtualize
  • Remix
  • Mission Impossible
The best problems to address are those that you have personal experiences with. Your commitment to finding a solution will be that much stronger and it will be the one thing that keeps you going through the crazy hights and the crazy lows of building a company.

Aaron Harris, founder of YCombinator

We are looking for founders who
  1. seems really great and formidable, so they can execute
  2. idea with chance of being a large business

best ideas

ideas across different industries https://www.ycombinator.com/rfs/
The very best startup ideas tend to have three things in common:
they’re something the founders themselves want,
that they themselves can build, and that
few others realize are worth doing. Microsoft, Apple, Yahoo, Google, and Facebook all began this way.
Why do so many founders build things no one wants?
Because they don’t use it themselves, they imagine other people wanting it.
it sounds plausible enough to fool you into working on them.
Paul Buchhei
Live in the future, then build what’s missing
If you’re not at the leading edge of some rapidly changing field, you can get to one. For example, anyone reasonably smart can probably get to an edge of programming (e.g. building mobile apps) in a year. Since a successful startup will consume at least 3-5 years of your life, a year’s preparation would be a reasonable investment.
Knowing how to hack also means that when you have ideas, you’ll be able to implement them. That’s not absolutely necessary (Jeff Bezos couldn’t) but it’s an advantage. It’s a big advantage, when you’re considering an idea like putting a college facebook online, if instead of merely thinking “That’s an interesting idea,” you can think instead “That’s an interesting idea. I’ll try building an initial version tonight.” It’s even better when you’re both a programmer and the target user, because then the cycle of generating new versions and testing them on users can happen inside one head.

Ted Talks

Nir Eyal: vitamin vs painkiller

Thursday, September 1, 2016

Derek Sivers; try everything in 12 years

Derek Siver

Making a company is a great way to improve the world while improving yourself. When you make a company, you make a utopia. It’s where you design your perfect world.

Why you need to fail?

when you’re green, you grow.
when you’re ripe, you rot.
No pain, no gain. (works for muscles and also brain)
  1. learning
  • to learn effectively, make mistakes and pay attention to these mistakes.
  • Making mistakes teach better than advanced preparation.
  • Doing what you know is fun, but doesn’t improve you.
  • Doing perfect in a practice room is not practicing
  1. growth mindset vs fixed minset
  • talent is from work vs innate
  • Anyone can master anything* vs you are great, or you aren’t.
  • The fixed mindset hurts you.
  • Mindset can be easily changed. (praise their effort/work not their talent)
  • You shouldn’t compare your inside with other’s outside, because we see our mistakes ourselves, but we only see other’s final product
  1. experiment
if you’re not failing, you are not trying hard enough.

books

  • mindset
  • the art of learning
  • the talent code
  • latent is overrated

weird, or just different?

Whatever true thing you can say about India, the opposite is also true.

Say no more often so you can embrace what you really love

Start now. No funding needed.

Keep your goals to yourself

Telling someone your goals makes them less likely to happen.
because someone acknowledge you that makes your mind tricked into feeling that it’s already done. You feel satisfactory. You’re less motivated to do the actual hard work necessary.

Derek Sivers speech to Berklee Colege of Music

6 things I wished I knew first day in Berklee
  1. Focus. Disconnect. Do not be distracted.
    you are surrounded by distraction. You are surrounded by cool casual people, telling you to be relax.
    My successful classmates are fiercely focus, determined and undistractable.
    While you are here, president will change, the world will change. Media will try to convice you these are important. But they are not.
  2. Do not accept their speed limit.
    I learn stuff in several weeks instead of sitting for a whole semester
    I graduated in 2.5 years.
  3. Nobody teach you anything. you have to teach youself.
  4. Learn from you heros, not only theirs.
  5. Don’t get stuck in the past. innovation is more important than imitation
  6. When done, be valuable.
    never underestimate the importance of making money in making music.
    Money is nothing more than a neutral proof that you are adding value in people’s life.
    Be one of the few know how to help yourself, instead of expecting others to do it for you.

Derek Sivers at TEDxTaipei 2012

life is ..

choice.

  • learn to ignoure logic and trust emotion
  • emotional brain stores instincts, fears and gut feelings
  • trust gut-feeling on something is usualy correct than when they tyr ot over-think it and use thier 5-dollar caclulator brains
  • if you learn to understand this feeling and saying this is good enoug and I’m happy with this. You actually make better choices and you feel better about it.
  • more choices is not always better. we are actually happier when we let other people make some choices for us, like see a doctor, follow religous rules, being told what to do
  • important vs urgent

time

  • how to use wisely? Always remember it’s limited
  • mostly future focused, somewhat present focus, somewhat past focus
  • state of flow, loving their work

memory

  • make more memory: to not get stuck in the routine too much, to do what’s novel, to do the risky thing, move to a new country, learn a new language, do ridiculous things

happiness

  • approach it side ways
  • ask yourself too much, how can I be happy? you’re going to be miserable

no meaning

  • I project all the meanings into it.
  • no inherit meaning
  • remove whatever meaning that holds you back
  • humans are 75% of water, I think humans are also 99% unused potential.
  • The thing holding you back from where you are to where you want to be, is always in your head. It’s usual because you put meaning on something that isn’t there.
  • If you learned that life has no meaning, then you can do whatever you want.

uncommon sense

2 why are you doing

Deathbed regret:
pursued something that someone convinced you should want, instead of what works for you.
what do you want? No matter what you choose, go for it.
  • money
    refuse fame, others in spotlight, just watch numbers
  • prestige
  • fame
  • leave a legacy
    like Trump, put your name on everything, make less money
  • freedom
    refuse responsibility, delegate everything,
    DIY = Decide it Yourself, but not Do.
key point is know, focus, don’t diffuse your energy to everything
Compass. Optimise.
know your goal

3 Nobody knows the future

4 Evolution

Love != Romeo & Juliet
Revolution!= War & Blood
Revolution = simply serving people better= uncommon sense

5 If not a hit, switch

12 years trying everything
If people aren’t loving what you’re doing, Stop!
Don’t persist. Don’t push it.
Warren Buffett
WE don’t swing unless it’s a clear home run.
Success comes from persistently improving and inventing,
not persistently pushing what’s not working

6 version 0.1

version 0.1 is what you can do right now, today, no programming, get real feedback.
If you’re not launching too soon, you’re launching too late. No perpect time

7 idea* Execution

I don’t want to hear ideas. I want to see the execution.

8 why CD baby is so successful

People remember you more for the little ways you make them smile, than all the business-school stuff you do.
So unusual (remarkable) that everyone tells their friends.
Can be shockingly unique.

Adam Grant: the surprising habits of original thinkers

late to the party

  • “ I have my most creative ideas when I’m procrastinating “
  • they are quick to start but slow to finish.
  • Failiure rate: First mover 47% vs improver 8%
  • It’s much easier to improve on somebody else’s idea than it its ot create something new from scratch. To be original, you don’t have to be first

feel doubt and fear

  • browser. who takes the initative to doubt the default and look for a better option
  • when you feel doubt, don’t let it go.
  • they’re afraid of failing, but they’re even more afraid of failing to try.
  • In the long run, our biggest regrets are not our actions, but our inaction.
  • It’s too important not to try.

have lots of bad ideas

  • They are not judged by their bad ideas
  • the greatest originals are the ones who fail the most, because they’re the ones who try the most