Forum Posts
- 4 Answers Finding all prime numbers within a given range
This is problem PRIME1 from SPOJ:
- shahsunny712 June 30, 2014
Input:
The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output:
For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.
To solve this, I applied a variation of the sieve of eratosthenes to calculate all primes from 2 to the maximum input number. Then iterate over that list and print out the numbers for each test case.
However, this gives TLE when the maximum input is 100000000(the allowed max). At several online forums, I read that to solve this, one needs to calculate primes only upto sqrt(100000000). I don't understand why this should work. Won't there be primes in the range say, 10000000 - 100000000 which are much greater than 100000000 ?| Flag | PURGE - 1 Answer Online Coding Test for Experienced Developer at Google,Microsoft etc
I have recently applied for a Windows Phone developer at big online shopping company. After the initial phone interview they told that I have to give an online coding test, and they sent me an link to online test. I was applying as 4+ years experience and the job description was too much about the tools, technology and application development over mobile, so I was expecting a question something related to above things, but the test was containing a question related to engineering math problem, and I found it weird to ask such a question to a person who left the college years ago and been involved in application development mainly.
- RAHULBUDHOLIYA June 25, 2014
My questions is that other big companies like Google,Microsoft ,amazon etc has similar hiring process for experienced developer? Should I Open my engineering books again and stop worrying about application development questions ?| Flag | PURGE - 0 Answers Why Global variables are not allowed in java?
I request others to refine the post as and when they find it wrong or out of context.
- rahulkeshar.career June 25, 2014
Imagine a real life scenario. In an office there is a coffee machine, which is accessible to everyone (all people). Now, since it is accessible to everyone so anyone can do anything to the milk in coffee machine (assume that someone added lime juice to milk). In order to prevent this we have to take some measures (like installing a CCTV to keep mischief out). But we are an indefinite specie, and can always find a way to sour the milk, so we can say, its kind of difficult to always keep an eye on the Coffee machine.
Also, there is always an option that we do not provide Coffee machine at all in the office, but if you wish to have a coffee, you can approach a coffee shop (As in case of Java, no global variables are allowed but you can create public class with static variable)
Now, taking this concept to our Java or C++, both are free to either implement or not implement Global variables, but Java chooses not to. Why?
• One, They are difficult to understand (as we have to look at the whole system, in above example we have to keep an eye to the behaviour of each and every person in the office) and maintain (as for the reasons stated in above example)
• Two, One of the features of Object Oriented programming is to keep data and the functions that operate on the data together (basically Encapsulation, to achieve high degree of cohesion), and global variables kind of defeats this.
• Three, they are error-prone (as souring of milk in above example), and are not associated with objects, and are therefore not object-oriented programming.
The only instance where a global value can be safe is where it is used as a constant.| Flag | PURGE - 1 Answer hashMap data retrive
i had declared hashMap object and put two values with the same key.
- Shankar Modi June 25, 2014
e.g
hm.put("key1","abc");
hm.put("key1","xyz");
when i retrieve the value of hashMap by the key "key1" i got value "xyz" because it override the value of "key1".
but if i want to retrieve the old value "abc" then how it possible. please solve my doubt .| Flag | PURGE - 2 Answers Amazon Group Coding Interview
Hi,
- suthejc June 25, 2014
I have a Group Interview at Amazon next week and I wanted to know if anyone has previously attended and what kinds of questions can be expected.
In this a total of 25-30 candidates who will be attending this process
and are divided into group of 3 randomly
and every team is given a project to implement in 5 hrs and in between there will be 1 hr interview with amazon guys
Anyone have any idea about this ?| Flag | PURGE - 1 Answer php
Create a php application with two DIV’s each 50% in width and floating right.
- divinebase.KwM June 18, 2014
In the left DIV, create a drop zone for user to drop files that should upload into a root directory and adds an entry into the mysql database with the files url, file name, file type and file size.
In the right DIV create a table that fills from mysql database, each time a user uploads a file the table should refresh with the updated mysql data.
· The user should be able to edit the file name (this should update the mysql database)
· The user should be able to delete the filean someone help with this question| Flag | PURGE - 0 Answers longest palindromic substring in O(n^^3)
#include<iostream>
- prashant June 02, 2014
#include<string>
#include<cstdio>
using namespace std;
string s;
int l;
int chk(int a,int b)
{
if(a==b)
return 1;
while(b>a)
{
if(s[a]!=s[b])
{
return 0;
}
b--;
a++;
}
return 1;
}
int main()
{
cin>>s;
int maxl=0,sa,sb;
l=s.length();
for(int i=0;i<l;i++)
{
for(int j=i;j<l;j++)
{
int p=chk(i,j);
if(p==1);
{
if(j-i>=maxl)
{
sa=i;
sb=j;
maxl=j-i+1;
}
}
}
}
for(int h=sa;h<=sb;h++)
printf("%c",s[h]);
}
i am getting absurd results :(
please help to point any mistake in the code?| Flag | PURGE - 3 Answers What happens when H1B is rejected?
After getting offer from Amazon, the H1B has been rejected. I'm assuming that that means end of this opportunity. But I still wanted to check if anyone else has been in similar situation and what happened to them?
- jameshall886 May 23, 2014
Thanks!| Flag | PURGE - 1 Answer What happens when H1B is rejected?
After getting offer from Amazon, the H1B has been rejected. I'm assuming that that means end of this opportunity. But I still wanted to check if anyone else has been in similar situation and what happened to them?
- jameshall886 May 23, 2014
Thanks!| Flag | PURGE - 2 Answers What happens when H1B is rejected?
After getting offer from Amazon, the H1B has been rejected. I'm assuming that that means end of this opportunity. But I still wanted to check if anyone else has been in similar situation and what happened to them?
- jameshall886 May 23, 2014
Thanks!| Flag | PURGE