---
# System prepended metadata

title: Interview 1

---

# Question 1

You want to make sure that Bob has your phone number but you can't directly ask him. Instead, you're allowed to pass a message to Eve, who will then pass it to Bob. Bob will then hand his message to Eve who will then return it to you. However, you don't want Eve to know what your phone number is. What message do you send to Bob?

# Question 2

Are there any plausible issues in the statement below. If so, what are they and how would you fix it?

## Go

```go
func main() {
	total := 0
	go func() {
		total += 1
	}()
	total += 1
}
```

## Rust

```rust
fn main() {
    let mut total = 0;

    let t = thread::spawn(move || {
        total += 1;
    });
    t.join().unwrap();

    total += 1;
}
```

# Question 3

Create a bank account that can be accessed from multiple threads/processes and has the ability to do the following:
- **Open an account**
- **Check the balance**
- **Deposit and Withdraw**
- **Close the account**

Please write an implementation for the interface below:

## Go

```go
type Account struct {}

// Open Opens the account with the given amount
func Open(amount int64) *Account {}

// Balance returns the balance of the account and 
// true or 0 and false if the account is closed
func (a *Account) Balance() (int64, bool) {}

// Transact either credits or debits the 
// amount of money to the account, returning the new balance and
// True or the current balance and false if the transaction
// failed
func (a *Account) Transact(amount int64) (int64, bool) {}

// Close Closes the account and withdraws the remaining balance.
// Returns the withdrawn amount and true if successful or 0 and false
// otherwise
func (a *Account) Close() (int64, bool) {}
```

## Rust

```rust
pub struct Account {}

impl Account {
    // Open opens the account with the given amount
    pub fn open(amount: i64) -> Account {}
    
    // Balance returns the balance of the account or None if the 
    // account is closed
    pub fn balance(&self) -> Option<i64> {}

    // Transact either credits or debits the 
    // amount of money to the account
    pub fn transact(&mut self, amount: i64) -> Result<i64, &'static str> {}
    
    // Close closes the account and returns the balance.
    // If the balance is zero, an error is returned
    pub fn close(&mut self) -> Result<i64, &'static str> {}
}

```