Pergunta de entrevista da empresa Klarna

1. Evaluate a polish notation based expression (operands precede operator) 2. Determine suffix (st or nd or th like 1st, 2nd, 23rd etc) for a given number.

Respostas da entrevista

Sigiloso

28 de jul. de 2020

Use a stack for storing operators and when you encounter an operator, pop operators, evaluate and store back to stack. Return head of stack as result. 2nd one is a simple if else/switch based solution

Sigiloso

27 de nov. de 2020

check the last digit of the number, if it's 1 then the suffix will be st, for 2 it'll be nd, for 3 it'll be rd; for all other it'll be th code: import random num = random.randint(1, 1000) d = num%10 if d==1: print(str(num) + "st") elif d==2: print(str(num) + "nd") elif d==3: print(str(num) + "rd") else: print(str(num) + "th")

Sigiloso

1 de jun. de 2021

Question 2: for(int i = 0; i <= 500; i++){ int num = i % 10; String suffix = "th"; if((i/10)%10 != 1) { switch (num) { case 1: suffix = "st"; break; case 2: suffix = "nd"; break; case 3: suffix = "rd"; break; } } System.out.println(i+suffix); }