Pergunta de entrevista da empresa Amazon

Write a code to for an input arithmetic equation to detect the braces and return the output in Binary i.e. for each opened braces there would be one closed braces. 2+((3-1)/8 ----- Output = False 2+((3-1)/8) -------- Output = True Don't remember the exact wordings of the question.

Respostas da entrevista

Sigiloso

16 de mai. de 2017

a = "2+((3-1)/8" b = a.codepoints.to_a len = b.length countopen = 0 countclose = 0 for i in 0..len-1 if b[i] == 40 countopen = countopen + 1 end if b[i] == 47 countclose = countclose + 1 end end print "#{countopen}" print "#{countclose}" if countopen == countclose print "False" else print "True" end

Sigiloso

31 de jul. de 2017

public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); test t1 = new test(); System.out.println(t1.checkBraces("2+(()3-1)/8")); } } class test{ public boolean checkBraces( String s1){ char[] c1 = s1.toCharArray(); int count = 0; for (int i=0; i

Sigiloso

20 de jul. de 2020

function main() { var str = '2+((3-1))/(8' let arr = str.split(''); var temp = []; for (var i=0; i 0) { return false; } else { return true; } } main();