Square logo

Square

San Francisco, CAFintech

Interview Questions

Battleship Game Implementation

Asked at Square
technical
game design
implementation

Implement single-player Battleship game.

Game Rules:

Ships:
- Carrier (5 spaces)
- Battleship (4 spaces)
- Cruiser (3 spaces)
- Submarine (3 spaces)
- Destroyer (2 spaces)

Placement Rules:
- Vertical or horizontal only
- No diagonal placement
- Must stay within board
- No overlapping
- No hanging off edges

Gameplay:
- Coordinate-based targeting
- Hit/Miss tracking
- Ship sinking detection
- Game end condition

Implementation Requirements:

  1. Board Setup
  • Ship placement validation
  • Grid representation
  • Coordinate system
  1. Game Logic
  • Move validation
  • Hit/Miss detection
  • Ship status tracking
  • Victory condition checking

Advanced Calculator Implementation

Asked at Square
technical
parsing
algorithms

Implement calculator with multiple operation types.

Features:

interface Calculator {
  // Basic Operations
  add(a: number, b: number): number
  subtract(a: number, b: number): number
  multiply(a: number, b: number): number
  divide(a: number, b: number): number
  
  // Advanced Operations
  abs(x: number): number
  sqrt(x: number): number
  
  // Expression Evaluation
  evaluate(expression: string): number
}

Requirements:
- Handle parentheses
- Operator precedence
- Error handling
- Expression parsing

Custom Encoding Decoder

Asked at Square
technical
encoding
strings

Implement decoder for custom encoding scheme.

Encoding Map:

A: "0"
B: "111"
C: "1100"
D: "1101"
E: "10100"
F: "10010"

Example:
"BAD" => "11101101"
decoder("11101101") => "BAD"

Requirements:

  • Parse binary string
  • Map to characters
  • Handle invalid input
  • Optimize for performance

Planet Destruction System

Asked at Square
technical
algorithms
optimization

Design system for planetary warfare simulation.

Features:

interface Planet {
  x: number;
  y: number;
}

interface Weapon {
  cost: number;
  destroy(target: Planet, planets: Planet[]): Planet[]
}

Requirements:
1. Distance Calculation
- Origin to planet distance
- Planet to planet distance

2. Weapon Types
- Single target
- Area effect (radius)

3. Optimization
- Minimum cost calculation
- Efficient targeting

Tournament Schedule Generator

Asked at Square
technical
algorithms
randomization

Generate random competition schedule for teams.

Requirements:

interface Schedule {
  team: string;
  opponent: string;
  round: number;
}

function generateSchedule(teams: string[]): Schedule[]

Rules:
- Each team plays twice against others
- Random scheduling
- No self-matches
- Complete coverage

River Crossing Puzzle

Asked at Square
technical
algorithms
puzzle

Implement solution for Chicken, Grain, Fox crossing puzzle.

Requirements:

interface State {
  boatman: boolean;  // true = right side
  chicken: boolean;
  grain: boolean;
  fox: boolean;
}

interface Solution {
  findValidMoves(state: State): State[]
  isValidState(state: State): boolean
  findSolution(): State[]
}

Rules:
- Boatman takes one item at a time
- Chicken eats grain if unattended
- Fox eats chicken if unattended

Plant Growth Simulator

Asked at Square
technical
simulation
recursion

Simulate plant growth with branching patterns.

Basil Rules:

  • 2 weeks to mature
  • Weekly branch cutting
  • New plant from each cutting

Extended Rules:

interface PlantRules {
  maturityWeeks: number;
  branchingInterval: number;
}

function simulateGrowth(
  weeks: number,
  rules: PlantRules
): number

Random Pairing Generator

Asked at Square
technical
algorithms
randomization

Generate unique random pairs from list of people.

Requirements:

function generatePairs(
  people: string[]
): [string, string][]

Rules:
- Complete pairing
- No self-pairing
- Different pairs each run
- Random distribution

Payment Analytics Queries

Asked at Square
technical
sql
analytics

SQL queries for payment and customer analysis.

Schema:

Payment (
  payment_id,
  sender_id,
  recipient_id,
  created_at,
  payment_state,
  amount
)

Customer (
  customer_id,
  created_at,
  customer_state
)

Queries:
1. 2022 payment metrics
2. Top recipients by amount
3. Failure rates by state
4. Active users (30-day window)

Pig Latin Transformer

Asked at Square
technical
strings
parsing

Transform words to Pig Latin format.

Rules:

function toPigLatin(text: string): string

Examples:
"hello" → "ellohay"
"hello world" → "ellohay orldway"
"hello, won't World!" → "ellohay, on'tway Orldway!"

Requirements:
- Preserve case
- Handle punctuation
- Maintain spacing

Friend Recommendation System

Asked at Square
technical
graphs
algorithms

Design friend recommendation system based on likes.

Data Structure:

interface Like {
  personA: string;
  personB: string;
  aLikesB: string;
  bLikesA: string;
}

Requirements:
1. Count mutual likes
2. Find best friends
3. Generate recommendations

Sock Matching Algorithm

Asked at Square
technical
algorithms
matching

Match socks based on color and foot type.

interface Sock {
  color: string;
  foot: 'left' | 'right';
}

function findPairs(socks: Sock[]): [Sock, Sock][]

Requirements:
- Match same color
- Different feet
- No duplicate usage
- Complete matching

Ball Game Simulator

Asked at Square
technical
simulation
probability

Simulate ball game with error probabilities.

interface GameRules {
  maxAttempts: number;
  bestOf?: number;
}

function simulateGame(
  playerAError: number,
  playerBError: number,
  rules: GameRules
): string

Features:
- Turn-based play
- Error handling
- Winner determination
- Best-of series support

Working Hours Analyzer

Asked at Square
technical
intervals
algorithms

Generate timeline of overlapping work schedules.

Input Format:

interface Schedule {
  name: string;
  start: string;  // "HH:MM"
  end: string;    // "HH:MM"
}

Example:
Input: [
  { name: "Oliver", start: "08:00", end: "17:00" },
  { name: "Lily", start: "08:30", end: "16:00" },
  { name: "David", start: "10:00", end: "19:00" }
]

Output:
"08:00-08:30: Oliver
 08:30-10:00: Oliver, Lily
 10:00-16:00: Oliver, Lily, David
 16:00-17:00: Oliver, David
 17:00-19:00: David"

Tournament Bracket Generator

Asked at Square
technical
algorithms
tournament

Design tournament system with power-based winning logic.

interface Candidate {
  name: string;
  power: number;
  id: number;
}

function generateTournament(
  candidates: Candidate[]
): string[]

Rules:
- Higher power wins
- Lower ID wins ties
- Single matches
- Complete coverage

Share Your Experience at Square