This file contains 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:math' as Math; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { |
This file contains 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'; | |
import 'dart:collection'; | |
import 'dart:isolate'; | |
import 'package:rxdart/rxdart.dart'; | |
void main() async { | |
await sumTwoLists(); | |
print("done"); | |
} |
This file contains 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:math'; | |
extension Divide<T> on List<T> { | |
List<List<T>> divideBy(int number) { | |
List<T> list = this; | |
List<List<T>> result = []; | |
while (list.isNotEmpty) { | |
result.add([...list.take(number)]); | |
try { | |
list = list.sublist(number); |
This file contains 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 JsonParserIsolate { | |
final String input; | |
JsonParserIsolate(this.input); | |
Future parseJson({Function(String)? onError}) async { | |
final completer = Completer(); | |
var port = ReceivePort(); | |
var errorPort = ReceivePort(); |
This file contains 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/pairs/problem | |
int findPairs(List<int> pairs, int diff) { | |
var counter = 0; | |
// save all values into Set | |
Set map = {}; | |
for (var el in pairs) { | |
map.add(el); | |
// use math to determine if there is a value as difference between value and diff | |
if (map.contains(el - diff)) { |
This file contains 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/gem-stones/problem | |
/// | |
/// There is a collection of rocks where each rock has various minerals embedded in it. Each type of mineral is designated by a lowercase letter in the range . | |
/// There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in the collection. | |
/// | |
int calcGemStones(List<String> input) { | |
var map = {}; | |
// go over the input collection and calculate amount of string where the character is present | |
// In order not to count "aaa" as three times we maintain ignoreSet set |
This file contains 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
/// Given a pointer to the head of a linked list and a specific position, determine the data value at that position. Count backwards from the tail node. The tail is at postion 0, its parent is at 1 and so on. | |
/// https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail | |
int? findNthElementInList(Node? head, int n) { | |
var current = head; | |
var counter = 0; | |
Node? result = head; | |
while (current != null) { | |
// when we processed nth element in list let's move result pointer to its next object | |
if (counter > n) { | |
result = result!.next; |
This file contains 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
/// You are given a string containing characters and only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string. | |
// | |
// Your task is to find the minimum number of required deletions. | |
// https://www.hackerrank.com/challenges/alternating-characters | |
int alternateCharactersLoop(String input) { | |
if (input.isEmpty) { | |
return 0; | |
} | |
var first = input[0]; |
This file contains 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<T> { | |
T value; | |
Node<T>? next; | |
Node(this.value, [this.next]); | |
} | |
/// Given pointers to the heads of two sorted linked lists, merge them into a single, sorted linked list. Either head pointer may be null meaning that the corresponding list is empty. | |
/// https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists/ | |
Node? mergeTwoLists(Node? l1, Node? l2) { |
This file contains 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:cli/linked_list.dart'; | |
/// https://www.hackerrank.com/challenges/compare-two-linked-lists/ | |
/// Compare two linked lists | |
int equalLinkedLists(Node a, Node b) { | |
Node? f1 = a; | |
Node? f2 = b; | |
while (true) { | |
if (f1 == null || f2 == null) { | |
return f1 == f2 ? 1 : 0; | |
} |
NewerOlder