Skip to content

Commit 8dc3eb2

Browse files
.
1 parent f858125 commit 8dc3eb2

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

Algorithms/Easy_Algorithms/EasyAlgorithmsClass.cs

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public static int nodeDepthsHelper(BinaryTree root, int depth)
389389
/// / \ / \
390390
/// -4 2 8 3
391391
/// / \
392-
/// 2 3
392+
/// 2 3
393393
///
394394
/// Sample output
395395
/// 6 // (((2*3) -2) + (8/3))
@@ -437,7 +437,23 @@ public BinaryTree(int value)
437437

438438
#region DepthFirstSearch
439439
/// <summary>
440+
/// You're given a Node class that has a name and an array of optional children
441+
/// nodes. When put together, nodes form an acyclic tree-like structure.
442+
///
443+
/// Implement the depthFirstSearch method on the Node class, which takes in an
444+
/// empty array. traverse the tree using Depth-First Search approach( specifically navigating
445+
/// the tree from left to right), stores all of the nodes, names in the input array, and returns it.
446+
///
447+
/// graph = A
448+
/// / | \
449+
/// B C D
450+
/// / \ / \
451+
/// E F G H
452+
/// / \ \
453+
/// I J K
440454
///
455+
/// Sample output
456+
/// ["A", "B", "E", "F", "I", "J", "C", "D", "G", "K", "H"]
441457
/// </summary>
442458
public class DepthFirstSearchClass
443459
{
@@ -454,9 +470,9 @@ public Node(string name)
454470
public List<string> DepthFirstSearch(List<string> array)
455471
{
456472
array.Add(name);
457-
for (int i = 0; i < children.Count; i++)
473+
foreach (var node in children)
458474
{
459-
children[i].DepthFirstSearch(array);
475+
node.DepthFirstSearch(array);
460476
}
461477
return array;
462478
}
@@ -473,29 +489,60 @@ public Node AddChild(string name)
473489

474490
#region MinimumWaitingTime
475491
/// <summary>
476-
///
492+
/// You're given a non-empty array of positive integers representing the amounts of the time
493+
/// that specific queries take to execute. Only one query can be executed at a time, but the
494+
/// queries can be executed in any order.
495+
///
496+
/// A queries waiting time is defined as the amount of time that it must wait before its
497+
/// execution starts. In other words, if a query is executed second, them its waiting time
498+
/// is the duration of the first query; if the a query is executed third, then its waiting
499+
/// time is the sum of the durations of the first two queries.
500+
///
501+
/// Write a function that returns the minimum amount of the total waiting time for all of the
502+
/// queries. For example, If you're given the queries of durations[1,4,5], then the total waiting
503+
/// time if the queries were executed in the order of [5,1,4] would be (0)+(5)(5+1)=11. The first
504+
/// query of duration 5 would be executed immediately, so its waiting time would be 0, the second
505+
/// (the duration of the first query) to be executed, and the last query would have to wait the
506+
/// duration of the first two queries before being executed.
507+
///
508+
/// queries = [3,2,1,2,6]
509+
/// Sample Input = 17
477510
/// </summary>
478511
public class MinimumWaitingTimeClass
479512
{
480513
public int MinimumWaitingTime(int[] queries)
481514
{
482515
Array.Sort(queries);
483-
int totailWaitingTime = 0;
516+
var totalWaitingTime = 0;
484517
for (int index = 0; index < queries.Length; index++)
485518
{
486-
487-
int duration = queries[index];
488-
int queriesLeft = queries.Length - (index + 1);
489-
totailWaitingTime += duration * queriesLeft;
519+
var duration = queries[index];
520+
var queriesLeft = queries.Length - (index + 1);
521+
totalWaitingTime += duration * queriesLeft;
490522
}
491-
return totailWaitingTime;
523+
return totalWaitingTime;
492524
}
493525
}
494526
#endregion
495527

496528
#region ClassPhotos
497529
/// <summary>
498-
///
530+
/// It's photo day at the local school, and you're the photographer assigned to take class
531+
/// photos. The class that you'll be photographing has an even number of students, and all
532+
/// these students are wearing red or blue shirt. Half red, half blue. You're responsible
533+
/// for arranging the student in two rows before taking the photo. Each row should contain the
534+
/// same number of students and should adhere to the following guidelines
535+
/// -> All Students wearing red shirts must be in the same row.
536+
/// -> All Students wearing blue shirts must be in the same row.
537+
/// -> Each student in the back row must be strictly taller than student directly in front
538+
/// of them in the first row.
539+
///
540+
/// You're given two input arrays: one containing the heights of all the students with red
541+
/// shirts and another one containing the heights of all the students with blue shirts. These
542+
/// arrays will always have the same length, and each height will be a positive integer. Write
543+
/// a function that returns whether or not a class photo follows the stated can be taken.
544+
///
545+
/// Note: You can assume that each class has at least 2 students.
499546
/// </summary>
500547
public class ClassPhotosClass
501548
{
@@ -713,7 +760,6 @@ public static int ProductSum(List<object> array)
713760

714761
public static int ProductSumHelper(List<object> array, int multiplier)
715762
{
716-
// Write your code here.
717763
int sum = 0;
718764
foreach (object item in array)
719765
{

0 commit comments

Comments
 (0)