Interview Question for SDE-3s


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

login_info = { 'tries' : 0 , 'last_successful' : time() }

def is_account_hacked( user_name , max_tries ){
    login_info = LOGIN_INFO[ user_name ]
    #atomic {
    success = login( user_name )
    current = time() 
    if ( success ){
       login_info.last_successful = current
       login_info.tries = 0 
       return false
    }
    login_info.tries += 1 
    return (  current - login_info.last_successful <= 36000000 &&
         login_info.tries >= n )
  }
}

- NoOne October 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

class LoginFailureInfo {
    long initialFailureTime
    int attempt = 0
}

class LoginHelper {
    def failureTable = [:] // Hash Map of User to LoginFailureInfo
    
    def login(String user, String password) {
        if (loginFailed) {
            def hacked = isAccountHacked(user) // isAccountHacked is called when login fails
            // Do something appropriate if hacked
        } else {
            // Successful login. Remove failure info from hash map
            if (failureTable[user]) {
                failureTable.remove(user)
            }
        }
    }
    
    def isAccountHacked(String user) {
        // Check for previous attempts and reset counter
        // if the current failure is occuring after 36000 millis
        def currentTime = new Date().getTime()
        
        if (failureTable[user]) { // If a previous failed attempt exists
            if (currentTime - failureTable[user].initialFailureTime > 36000) {
                failureTable[user].initialFailureTime = currentTime // reset the time
                failureTable[user].attempt = 1 // reset the counter to 1
            } else {
                failureTable[user].attempt++
            }
        } else {
            // If this is the first failure, add a new entry to map
            failureTable << [user: new LoginFailureInfo(initialFailureTime: currentTime, attempt: 1)]
        }
        
        // Check the number of failures from hash map
        if (failureTable[user].attempts >= 5) {
            true
        } else {
            false
        }
    }
}

- stspyder February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class LoginFailureInfo {
    long initialFailureTime
    int attempt = 0
}

class LoginHelper {
    def failureTable = [:] // Hash Map of User to LoginFailureInfo
    
    def login(String user, String password) {
        if (loginFailed) {
            def hacked = isAccountHacked(user) // isAccountHacked is called when login fails
            // Do something appropriate if hacked
        } else {
            // Successful login. Remove failure info from hash map
            if (failureTable[user]) {
                failureTable.remove(user)
            }
        }
    }
    
    def isAccountHacked(String user) {
        // Check for previous attempts and reset counter
        // if the current failure is occuring after 36000 millis
        def currentTime = new Date().getTime()
        
        if (failureTable[user]) { // If a previous failed attempt exists
            if (currentTime - failureTable[user].initialFailureTime > 36000) {
                failureTable[user].initialFailureTime = currentTime // reset the time
                failureTable[user].attempt = 1 // reset the counter to 1
            } else {
                failureTable[user].attempt++
            }
        } else {
            // If this is the first failure, add a new entry to map
            failureTable << [user: new LoginFailureInfo(initialFailureTime: currentTime, attempt: 1)]
        }
        
        // Check the number of failures from hash map
        if (failureTable[user].attempts >= 5) {
            true
        } else {
            false
        }
    }
}

- St.Spyder February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public class AccountHackHelper
{
int n;
SortedList<DateTime, DateTime> store;

public AccountHackHelper(int n)
{
this.n = n;
store = new SortedList<DateTime, DateTime>(n);
}



public bool IsAccountHacked(string userName, DateTime currentDate)
{
StoreFailedLogin(currentDate);

if (store.Count == n && (currentDate - store.First().Value).TotalSeconds < 3600 )
{
return true;
}

return false;
}

private void StoreFailedLogin(DateTime currentDate)
{
if (store.Count == n) { store.RemoveAt(0); }
store.Add(currentDate, currentDate);
}

}

- vh.vahan February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Space complexity of your solution is O(n).

- sachindraac February 18, 2016 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More