Skip to content

DavidCanHelp/rust-study

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Interview Questions TUI

Rust License: MIT Version

A Terminal User Interface (TUI) application for practicing common coding interview questions in Rust. Each question includes extensive beginner-friendly comments explaining how to solve it from scratch, along with Rust-specific concepts and best practices.

Rust Interview Questions TUI Categories

Features

  • Interactive TUI: Navigate questions with arrow keys, run them with Enter
  • 20 Interview Questions across 4 categories:
    • Classic Problems (FizzBuzz, Fibonacci, Palindrome, Two Sum, Reverse String)
    • Data Structures (Linked List, Binary Tree, Stack, Queue, Valid Parentheses)
    • Algorithms (Binary Search, QuickSort, MergeSort, BFS, DFS)
    • String Manipulation (Anagram Check, Longest Substring, Common Prefix, Permutations, Group Anagrams)
  • Educational Comments: Every question includes step-by-step explanations
  • Live Execution: See the output of each algorithm immediately
  • Full-Screen Results: Clean, readable output view

Prerequisites

  • Rust 1.70 or later (install from rustup.rs)

Installation & Running

# Clone the repository
git clone https://github.com/davidcanhelp/rust-study.git
cd rust-study

# Build and run
cargo run

# Or build optimized release version
cargo build --release
./target/release/rust-interview-questions

Usage

Navigation

  • ↑/↓ Arrow Keys: Navigate through the question menu
  • Enter: Run the selected question
  • ESC or B: Return to menu from results view
  • Q: Quit the application

Menu View

┌─────────────────────────────────────────────────────────┐
│              Rust Interview Questions                   │
└─────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────┐
│ Select a Question (↑/↓ to navigate, Enter to run, Q to quit) │
│                                                          │
│ >> 1. FizzBuzz - Classic programming challenge          │
│    2. Fibonacci - Generate Fibonacci sequence           │
│    3. Palindrome - Check if string is palindrome        │
│    ...                                                   │
└──────────────────────────────────────────────────────────┘

Results View

Each question runs and displays:

  • The output of the algorithm
  • Explanation of the approach
  • Time and space complexity analysis

Project Structure

rust-study/
├── Cargo.toml                 # Project dependencies and metadata
├── README.md                  # This file
├── LICENSE                    # MIT License
└── src/
    ├── main.rs                # TUI event loop and terminal setup
    ├── app.rs                 # Application state management
    ├── ui.rs                  # UI rendering with ratatui
    └── questions/
        ├── mod.rs             # Question registry
        ├── classic.rs         # Classic interview questions
        ├── data_structures.rs # Data structure implementations
        ├── algorithms.rs      # Sorting and searching algorithms
        └── strings.rs         # String manipulation problems

Learning from the Code

For Beginners

Each question file includes:

  1. Problem Statement: Clear description of what to solve
  2. How to Solve from Scratch: Step-by-step approach
  3. Rust Concepts: Explanation of language features used
  4. Complexity Analysis: Time and space complexity
  5. Working Implementation: Fully commented code

Key Rust Concepts Covered

  • Ownership & Borrowing: Understanding &T, &mut T, and moved values
  • Option & Result: Handling nullable values and errors
  • Pattern Matching: Using match and if let
  • Iterators: Powerful functional-style data processing
  • Collections: Vec, HashMap, VecDeque
  • Traits: Using and implementing traits
  • Generics: Writing reusable code
  • Box & Smart Pointers: Heap allocation and recursive types

Example: Reading the FizzBuzz Implementation

Open src/questions/classic.rs and find the run_fizzbuzz() function. You'll see:

// ============================================================================
// FIZZBUZZ
// ============================================================================
// PROBLEM: Print numbers from 1 to 100, but:
// - For multiples of 3, print "Fizz"
// - For multiples of 5, print "Buzz"
// - For multiples of both 3 and 5, print "FizzBuzz"
//
// HOW TO SOLVE FROM SCRATCH:
// 1. Loop through numbers 1 to 100
// 2. Check if divisible by both 3 and 5 first (order matters!)
// ...

Customization

Adding Your Own Questions

  1. Open the appropriate file in src/questions/ (or create a new one)
  2. Write your question function:
    fn run_my_question() -> String {
        let mut output = String::from("My Question:\n\n");
        // Your implementation here
        output
    }
  3. Register it in the module's get_questions() function:
    Question::new("My Question", "Description", run_my_question)

Modifying the UI

  • Edit src/ui.rs to change colors, layout, or styling
  • Uses the ratatui library
  • All UI rendering is in render_menu() and render_results()

Technologies Used

  • ratatui: Terminal UI framework
  • crossterm: Cross-platform terminal manipulation
  • Rust Standard Library: Collections, iterators, and more

Learning Resources

After Using This Project

  1. The Rust Book: doc.rust-lang.org/book
  2. Rust by Example: doc.rust-lang.org/rust-by-example
  3. Rustlings: Small exercises to learn Rust
  4. LeetCode: Practice more interview questions

Algorithm Resources

Contributing

Feel free to:

  • Add more interview questions
  • Improve explanations
  • Fix bugs or typos
  • Enhance the UI

License

MIT License - see LICENSE file for details.

Author

DavidCanHelp


Happy Learning! 🦀

Remember: The best way to learn is by doing. Try implementing these algorithms yourself before looking at the code, then compare your solution with the provided implementation.

About

A study in Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages