This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// https://www.hackerrank.com/challenges/minimum-swaps-2/ | |
/// | |
/// You are given an unordered array consisting of consecutive integers [1, 2, 3, ..., n] without any duplicates. | |
/// You are allowed to swap any two elements. Find the minimum number of swaps required to sort the array in ascending order. | |
int minimumSwaps(List<int> input) { | |
int swaps = 0; | |
var list = List.generate(input.length, (index) => index + 1); | |
var map = {}; | |
for (var el in list) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Task | |
/// Given a set of closed intervals, find the smallest set of numbers that covers all the intervals. If there are multiple smallest sets, return any of them. | |
Set findMinSetToCoverIntervals(List<List<int>> input) { | |
var start; | |
var end; | |
/// we need to find minimum value of the end intervals, it will be our start in result | |
/// and maximum value of the start intervals, it will be our end in result | |
for (List<int> interval in input) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
void main() async { | |
print('a'); | |
await waitTime(Duration(seconds: 3)); | |
print('b'); | |
} | |
Future waitTime(Duration duration) { | |
Completer completer = Completer(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
findIfSumIsInArray(); | |
} | |
/** | |
Given a list of numbers and a number k, return whether any two numbers from the list add up to k. | |
For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
Node? left; | |
Node? right; | |
int value; | |
Node({required this.value, this.left, this.right}); | |
} | |
/* | |
Given a binary tree, return the level of the tree with minimum sum. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:ui' as ui; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
const double APP_BAR_HEIGHT = 40.0; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class TextEditor extends StatefulWidget { | |
final String text; | |
final int maxLines; | |
final Function(String) onSave; | |
final Function(String) onSubmitted; | |
final TextEditingController controller; | |
final bool showDone; |