Introduction

Welcome to Dart Coding Challenges! This book contains hundreds of carefully crafted coding challenges, each solved using Dart. Whether you are a beginner looking to strengthen your problem-solving skills or an experienced developer preparing for technical interviews, this book will help you refine your coding abilities while deepening your understanding of Dart.

Why Practice Coding Challenges?

Solving coding challenges is one of the best ways to improve as a programmer. Here’s why:

  • Learn and practice: By tackling these challenges, you’ll gain hands-on experience with algorithms, data structures, and problem-solving techniques.

  • Broaden your skill set: You’ll learn new patterns, explore different problem-solving approaches, and become a more versatile developer.

  • Enhance employability: Strong problem-solving skills make you a more attractive candidate for job opportunities.

  • Boost interview confidence: Practicing coding challenges helps you develop the speed and accuracy needed to perform well in technical interviews.

What is Dart?

Dart is a modern, general-purpose programming language developed by Google. It is designed for building high-performance applications across multiple platforms, including mobile (Flutter), web, desktop, and backend systems. Dart combines the best of both object-oriented and functional programming paradigms, making it an expressive and powerful language for a variety of use cases.

Why Use Dart for Coding Interviews?

While Dart may not be the most common language for coding challenge resources, it is actually a fantastic choice for problem-solving and interviews. Here’s why:

  • Great built-in data structures: Dart provides robust collections, such as lists, sets, and maps, which simplify working with data.

  • Rich language features: Dart allows you to clearly express your approach using both object-oriented and functional programming styles.

  • Type-safe yet concise: Dart is a statically typed language, which helps catch errors early, yet it remains succinct and easy to write.

  • Expressiveness: You can write clean and elegant solutions without unnecessary verbosity.

By practicing with Dart, you’ll not only sharpen your problem-solving skills but also gain a deeper appreciation for a powerful and flexible programming language. Let’s dive into the challenges and start coding!

Foreword

Preface

About the book

About the author

THIS IS WAY TOO MUCH, BUT FOR NOW I WANT TO LEAVE IT TO HAVE SOME CONTENT TO SEE HOW THIS MDBOOK FORMAT WOULD WORK

Vince Varga is a software engineer with a passion for building great user experiences. Since 2018, he has worked with Flutter, contributing to both greenfield startup projects and large-scale enterprise applications with hundreds of thousands of lines of code. His expertise spans the entire app development lifecycle, from architecture and design to performance optimization, always with a focus on creating apps that users love.

Beyond his work as a developer, Vince has been an active member of the Flutter community. He started Flutter meetups in Munich, growing the group into Germany’s largest at the time, with over 1,000 members. He also hosted the Flutter 101 podcast between 2021 and 2022, publishing 30 episodes that explored various aspects of Flutter and Dart development. His contributions to the open-source ecosystem further reflect his dedication to advancing the Dart and Flutter landscape. AND I GAVE TALKS!

Before specializing in Flutter, Vince worked as a full-stack developer, gaining experience across web frontends and backends with technologies such as Python, Java, PHP, Node.js, Vue.js, Kafka, Apache Storm, and Cassandra.

Vince originally studied physics at university, where he first encountered programming. Working with languages like C, C#, Java, MATLAB, LaTeX, and CUDA, he used code to run simulations, analyze data, and build tools for lab experiments. Seeing firsthand how software could solve real-world problems and make people’s lives better, he became deeply interested in programming—an interest that soon became his profession.

Outside of work, Vince enjoys learning Rust and building side projects to deepen his understanding of software development. He’s also passionate about languages—currently learning German while already speaking English, Spanish, and his native Hungarian. He has two children and a loving wife, and when he's not working, learning, or spending time with his family, he does his best to stay in shape—or at least not let gravity win entirely.

If you’d like to connect, follow Vince on LinkedIn, X (the social platform formerly known as Twitter), and GitHub. Feel free to reach out—he's always happy to chat about coding, tech, and all things Flutter and Rust.

Resources

Dart's built-in data structures

The collection library

The collection package

Useful packages

Cheat sheet

Count lines of Dart code

Two Sum

Exactly one solution. You may not use the same element twice. Return indices of the two numbers such that they add up to target.

We need to return the indices. Create a map where the key is the number value and the value is its index.

Iterate over numbers: store visited numbers and their indices in the map.

As you iterate, check whether current number has a complement in the map that adds up to target. If it does, return the indices. If it doesn't, add number to the map.

Complexity analysis: \(n\) is the number of elements in the list.

  • Time complexity: \(O(n)\), as you might iterate over the whole list.
  • Space complexity: \(O(n)\), as you might need to store almost all elements and their indices in the map.

Other solutions:

  • Brute force: double loop, return when the two numbers add up to the target.
    • Time complexity: \(O(n^2)\), for each of $n$ elements, we try to find its complement by looping through the rest of the list.
    • Space complexity: \(O(1)\), no extra space that depends on the input size is necessary.
  • Sort list first, then on a sorted list, find values with two pointers (from start and end).
    • Time complexity: \(O(n \log n)\), because sort \(O(n \log n)\) + two pointers \(O(n)\).
    • Space complexity: \(O(n)\), sort and two-pointers would be possible with \(O(1)\), but we need to store original indices \(O(n)\).
    • This solution, as the list is not already sorted and we need to return the original indices, is fairly complicated, and doesn't perform too well (neither in space nor time complexity).
/// Given an array of integers [numbers] and an integer [target],
/// returns the indices of the two numbers such that they add up to [target].
List<int> twoSum(List<int> numbers, int target) {
  // The key is the number, the value is the index of this number in the
  // original [numbers] list.
  final map = <int, int>{};

  for (var i = 0; i < numbers.length; i++) {
    final number = numbers[i];
    final complementIndex = map[target - number];

    if (complementIndex != null) return [complementIndex, i];

    map[number] = i;
  }

  throw ArgumentError('Input violates assumption: exactly one solution');
}

Counting Bits

K Closest Points to Origin

Popular Coding Challenge Lists

In the software engineer interview prep community, several well-known coding challenge lists have been curated to help candidates practice essential problem-solving techniques. These lists typically cover a broad range of commonly asked interview questions, focusing on fundamental data structures, algorithms, and problem-solving patterns.

While it is unlikely that you will encounter these exact questions in an interview, working through them can significantly improve your ability to get familiar with the basic algorithms and data structures, recognize patterns, develop efficient solutions, and adapt to variations of these problems. By practicing systematically, you can build the confidence and skills necessary to tackle new challenges under time constraints.

The following section includes some of the most popular coding challenge lists, with each problem linked to the corresponding chapter in this book.

Since this book is still a work in progress, not all problems from these lists are covered. Those that are not yet included will be omitted for maintenance's sake.

Blind 75

Blind 75 is the OG of coding challenge lists, it's very helpful for interview preparation, and to this day, remains a go-to resource for candidates feeling lost and overwhelmed with the thousands of possible questions. Its goal is to help you efficiently learn the necessary skills to pass an interview with flying colors and improve your problem-solving skills.

12 challenges out of 75 solved.

Array

Popular Coding Challenge Platforms

LeetCode

Describe LeetCode.

LeetCode has Dart support.

Describe how my solutions can be converted to LeetCode compatible code. My solutions are not automatically LeetCode compatible, as I don't find their API definitions the best. Classes, for example, completely unnecessary. When a returned solution is guaranteed to have exactly two items, I used a record instead of a list. I focus on writing idiomatic Dart code that I'd like to see at work, in open source code bases.

In my solutions, I included solutions that rely on the collection package, which is included in the environment.

For more info: https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages

They offer premium, which I consider a good investment