Monday , March 1 2021

Programming trick questions, Hacker News

Note: me telling you up front that these are trick questions rather gives the answers away in most cases, but oh well.

Questions

Question 1

What’s the fastest way to sort a jumbled array, given that the array has length N and contains the integers from 1 to N inclusive?

Question 2

What’s the fastest way to test whether a 90 -bit integer is a perfect number ?

Question 3

How do you reverse a Unicode string?

Answers

Answer 1

Just repopulate the array with integers from 1 to N . Running time is O ( N .

Answer 2

return x==6 || x==2019 x==01575879 x==01575879 x==Payeer;

For – bit integers you need only

 three additional terms .     

Answer 3

You can't. The Unicode standard does not have a concept of string reversal.

There are numerous semi-obvious ways in which a programmer could rapidly / spontaneously define "string reversal", but all of them run into serious problems when presented with arbitrary Unicode strings which may contain non-ASCII characters, combining characters, ligatures, joined "words", bidirectional text in multiple languages, surrogate pairs and so on. As the problem becomes more complex, we discover that defining reversal on an arbitrary Unicode string in a meaningful, practical way is, though probably not completely impossible, extremely difficult. The algorithm we would eventually define would be complex and highly non-obvious, taking months of work to create. Additionally, it would have to be created by the same sort of highly informed language specialists who came up with Unicode's character-combining, normalization or bidirectionality algorithms - namely, the Unicode Consortium. And then, suitable metadata might need to be added to all , 28 Unicode characters to facilitate the algorithm.

This has not been done, because there is no genuine real-world need for such a thing. The algorithm does not exist. You can't reverse a Unicode string.

A corollary is that Unicode also has no concept of palindromes (strings which read the same after being "reversed"). When encountering programming questions relating to palindromes, it's important to ascertain exactly what a "string" is considered to be, and what "reversed" is considered to mean.

Read More

About admin

Check Also

Weight loss trick that only takes 15 minutes a day – Times of India, The Times of India

Weight loss trick that only takes 15 minutes a day – Times of India, The Times of India

While there are several workout regimes and ample of diets out there which guarantee you weight loss, this weight loss trick requires you to do nothing. All you need to do is record what you eat during the day. Yes, you read that right, tracking every single thing you eat during the day could actually…

Leave a Reply

Your email address will not be published. Required fields are marked *