C# Tutorial - Solving the turing.com coding challenge practise tests using C#

  Рет қаралды 14,611

Verxivr Media

Verxivr Media

Күн бұрын

C# tutorial to solve the turing.com coding challenge practise tests 1 and 2
Source Code:
- Problem 1: github.com/VerxivrEltaire/Cal...
- Problem 2: github.com/VerxivrEltaire/Val...

Пікірлер: 66
@ricardosilva8339
@ricardosilva8339 2 жыл бұрын
Some tips: On the first problem It's possible to avoid the unnecessary nested loops: You can solve the problem with just one loop, which will give an O(n) algorithm. Also, try to use more meaningful names for variables. Don't forget to handle invalid inputs: It's not a good strategy to consider any input other than C, D, or + as an integer.
@isaactsibu-darko6854
@isaactsibu-darko6854 Жыл бұрын
would you happen to know the javascript solution for this?
@zainulabideniftikhar821
@zainulabideniftikhar821 10 ай бұрын
do they ask same question in c# stack or they keep changing it?
@davidodediran6346
@davidodediran6346 Жыл бұрын
You have done a great job here, my brother. One thing I got from your presentation is the principle of separation of concern and understanding the actual questions or requirements is essential. I never thought I could access the last two indexes; I only knew of one in a list. Thanks for the method, and I am grateful.
@zainulabideniftikhar821
@zainulabideniftikhar821 10 ай бұрын
do they ask same question in c# stack or they keep changing it?
@oltitia
@oltitia 2 жыл бұрын
Wow! happy to discover your channel. I am preparing to take a Javascript live coding challenge, at least you have given me a hint of what to expect.
@verxivrmedia
@verxivrmedia 2 жыл бұрын
We are glad to be of help. We wish you all the best as you write the live coding challenge
@ebubeandyoutube1415
@ebubeandyoutube1415 Жыл бұрын
Have you taken the test? I'm about to take the test and the template is somewhat of a challenge for me. Can we connect on discord or any other app?
@kaleemabdul8065
@kaleemabdul8065 Жыл бұрын
You have done a great job, Your video is helping me to prepare for a C# challenge, Thank you. int sum = 0; ArrayList arrList = new ArrayList(); for (int i=0; i< ops.Length;i++) { int Num = 0; sum = 0; if (int.TryParse(ops[i],out Num)) { arrList.Add(Num); } else if(ops[i]=="+") { sum =(int) arrList[arrList.Count - 1]; sum += (int)arrList[arrList.Count - 2]; arrList.Add(sum); } else if (ops[i] == "D") { sum = 2*(int)arrList[arrList.Count - 1]; arrList.Add(sum); } else if (ops[i] == "C") { arrList.RemoveAt(arrList.Count - 1); } } sum = 0; for (int i = 0; i < arrList.Count; i++) { sum += (int)arrList[i]; } return sum;
@pinecraig2320
@pinecraig2320 2 жыл бұрын
Thank you so much. Great content
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Glad you enjoyed it!
@tracybufazi9165
@tracybufazi9165 2 жыл бұрын
Wow!! Thànk you so much for this. Nice content 👌 The background music is perfect for learning.
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Thank you so much
@okechukwuihechukwu374
@okechukwuihechukwu374 2 жыл бұрын
Im looking forward to develop my skills in programming from your channel.Thanks
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Best of luck! We will do our best to help you
@lifeofintelligence8523
@lifeofintelligence8523 Жыл бұрын
I liked the solution very much I've also tried one. public int CalPointsFunc(string[] args) { int output; List record = new List(); foreach(string arg in args) { if (Int32.TryParse(arg, out output)) { record.Add(Int32.Parse(arg)); } else { if (arg == "C") record.RemoveAt(record.Count - 1); else if (arg == "D") record.Add(record.Last() * 2); else if (arg == "+") record.Add(record[record.Count - 2] + record.Last()); } } return record.Sum(); } Thanks
@frankjames8789
@frankjames8789 2 жыл бұрын
This is great content. Looking forward to try the live coding challenge in Kotlin
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Coming soon!
@kennethihemadu7190
@kennethihemadu7190 2 жыл бұрын
Can't wait for the full C# course. Im interested in learning that language
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Stay tuned. It's coming
@raymondjavel2559
@raymondjavel2559 2 жыл бұрын
I really appreciate the background music. Helps my attention
@verxivrmedia
@verxivrmedia 2 жыл бұрын
We are glad it does
@zeynephan3428
@zeynephan3428 Жыл бұрын
Why is the music playing in the background when doing a fully concentrated work?
@lordgreat6051
@lordgreat6051 2 ай бұрын
why didnt u make integer list you couldve only needed to parse once while adding right?
@prov4186
@prov4186 2 жыл бұрын
Fantastic work
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Many thanks
@nelsonmudanya3015
@nelsonmudanya3015 2 жыл бұрын
I recreated your solution using much shorter syntax. Here it is ... class Solution { public int CalPoints(string[] ops) { var opsList = new List(); var count = 0; foreach(var op in ops) { if (op.Equals("+")) { var val = opsList[opsList.Count -1] + opsList[opsList.Count - 2]; opsList.Add(val); } else if (op.Equals("D")) { var val = opsList[opsList.Count - 1] * 2; opsList.Add(val); } else if (op.Equals ("C")) { opsList.RemoveAt(opsList.Count - 1); } else { opsList.Add(int.Parse(op)); } } foreach(var op in opsList) { count += op; } return count; } } class CalPoints { public static void Main(string[] args) { var solution = new Solution(); var space = new Char[] { ' ' }; string[] ops = Console.ReadLine().Split(space); int output = solution.CalPoints(ops); Console.WriteLine(output.ToString()); } }
@robertovillavicencio2017
@robertovillavicencio2017 Жыл бұрын
I did something like that yesterday, un VS works ok but un the turing web give me a sintaxis error in " value.Count - 1 " for get the last member, specificly un the -
@tsunablast3693
@tsunablast3693 2 жыл бұрын
Ty for the video! Your explanation is great and is helping me to prepare for a C# challenge. Just a question, why not to put the foreach (var val in opsList) [...] segment outside all if statements instead of copying and repeating it for each of them? I may be missing something.
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Thank you so much for your observation Sir. The reason we repeat it for each if statement is because each if statement does something unique to opsList, and we need to initialize the value of the "value" variable to zero before we call the foreach statement. Hopes this help. Thanks
@zainulabideniftikhar821
@zainulabideniftikhar821 10 ай бұрын
did you get the same questions ?
@tsunablast3693
@tsunablast3693 10 ай бұрын
@@zainulabideniftikhar821 In the practice test we all get the same questions, I believe. Unless it changed since then.
@nahimyaya1794
@nahimyaya1794 2 жыл бұрын
Great work
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Thank you! Cheers!
@geraldfina4236
@geraldfina4236 2 жыл бұрын
Don't stop the good work
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Thank you so much
@mercedesbrian6212
@mercedesbrian6212 2 жыл бұрын
I like your presentation
@verxivrmedia
@verxivrmedia 2 жыл бұрын
So nice of you
@huseyinsarioglu
@huseyinsarioglu Жыл бұрын
I try to write before watching your solution. Still refactor should be done. Here it is: public int Calculate(string[] scores) { const string CANCEL = "C"; const string DOUBLE = "D"; const string ADD = "+"; if (scores == null || scores.Length == 0) { return 0; } var records = new List(); foreach (var score in scores) { switch (score) { case CANCEL: if(records.Count == 0) throw new Exception($"{CANCEL} operator cannot be used first!"); records.RemoveAt(records.Count - 1); continue; case DOUBLE: if (records.Count == 0) throw new Exception($"{DOUBLE} operator cannot be used first!"); records.Add(records[^1] * 2); continue; case ADD: if (records.Count < 2) throw new Exception($"{ADD} operator cannot be used for first two values!"); records.Add(records[^1] + records[^2]); continue; default: if (!int.TryParse(score, out int number)) { throw new ArgumentException($"Unknown score specifier: {score}"); } records.Add(number); continue; } } return records.Sum(); }
@mihirrajput932
@mihirrajput932 Жыл бұрын
return records.AsQueryable().Sum() ; //just a small correction :)
@huseyinsarioglu
@huseyinsarioglu Жыл бұрын
@@mihirrajput932 Hi Mihir. This code has been tested. No need to add AsQueryable(). System.Linq.Enumerable already has a direct extension method for sum and the other aggreagte functions :)
@mgadriescu
@mgadriescu Жыл бұрын
My solution, nice and clean public int CalPoints(string[] ops) { var record = new List(); foreach (var item in ops) { switch (item) { case var _ when int.TryParse(item, out int value): record.Add(value); break; case "+": record.Add(record[^2] + record[^1]); break; case "D" or "d": record.Add(2 * record[^1]); break; case "C" or "c": record.RemoveAt(record.Count - 1); break; } } return record.Sum(); } }
@peacenetwork2668
@peacenetwork2668 2 жыл бұрын
Can you share this script in Java?
@digitalizedhorizon3895
@digitalizedhorizon3895 9 ай бұрын
Thanks it was great! and here is an other solution: public static int CalPoints(string[] ops) { Stack stack = new Stack(); foreach (string op in ops) { if (int.TryParse(op, out int score)) { stack.Push(score); } else if (op == "+") { int prev1 = stack.Pop(); int prev2 = stack.Peek(); int newScore = prev1 + prev2; stack.Push(prev1); stack.Push(newScore); } else if (op == "D") { int prev = stack.Peek(); stack.Push(prev * 2); } else if (op == "C") { stack.Pop(); } } int finalScore = 0; while (stack.Count > 0) { finalScore += stack.Pop(); } return finalScore; }
@cisicDailyHealthTips
@cisicDailyHealthTips Жыл бұрын
Hello... I'm new to turing. I'm an intermediate c# programmer. I would like to know your journey with turing... I'm wondering if this can help me in my career path
@zainulabideniftikhar821
@zainulabideniftikhar821 10 ай бұрын
did you get the same questions ?
@clearz3600
@clearz3600 2 ай бұрын
A stack version for fun var opList = new[] { "5", "2", "C", "D", "+" }; var stk = new Stack(); foreach(var op in opList) { switch(op) { case "+": var lVal = stk.Pop(); var rVal = stk.Peek(); stk.Push(lVal); stk.Push(lVal + rVal); break; case "C": stk.Pop(); break; case "D": stk.Push(stk.Peek() * 2); break; default: stk.Push(int.Parse(op)); break; } } Console.WriteLine(stk.Sum());
@abdulrafeyartist5025
@abdulrafeyartist5025 Жыл бұрын
Both can be done using single loop. Solution 1 : List result = new List(); for (int i = 0; i < ops.Length; i++) { if (ops[i] == "+") { result.Add(result[result.Count - 1] + result[result.Count - 2]); } else if (ops[i] == "D") { result.Add(result[result.Count - 1] * 2); } else if (ops[i] == "C") { result.RemoveAt(result.Count - 1); } else { result.Add(int.Parse(ops[i])); } } return result.Sum(); ................................. Solution 2: char[] chars = s.ToCharArray(); Stack openParenthesis = new Stack(); foreach (var c in chars) { if(c == '(' || c == '{' || c == '[') { openParenthesis.Push(c); } else if(c == ')') { if(openParenthesis.Peek() == '(') { openParenthesis.Pop(); } } else if(c == '}') { if (openParenthesis.Peek() == '{') { openParenthesis.Pop(); } } else if (c == ']') { if (openParenthesis.Peek() == '[') { openParenthesis.Pop(); } } } return openParenthesis.Count == 0;
@isaacmayowa7083
@isaacmayowa7083 2 жыл бұрын
Please is the practice question the same as the real test that one will do? Urgent!!!
@zainulabideniftikhar821
@zainulabideniftikhar821 10 ай бұрын
did you get the same questions ?
@olamidefalowo1407
@olamidefalowo1407 Жыл бұрын
Nice... i wished you could do it in php. But i guess thats not your stack.
@wijlini
@wijlini 2 жыл бұрын
Hello bro, what about the Turing Tests that is before the Coding Challenge ?, that will be more interesting if you show us some skills on that thank you
@verxivrmedia
@verxivrmedia 2 жыл бұрын
This is noted Sir. Thanks for the feedback
@abuyahya2014
@abuyahya2014 Жыл бұрын
public static int ProcOpt(string[] opt) { List recordList = new(); for (int i = 0; i < opt.Length; i++) { if (opt[i] == "c") recordList.Remove(recordList.Last()); else if (opt[i] == "d") recordList.Add(recordList.Last() * 2); else if (opt[i] == "+") recordList.Add(recordList.TakeLast(2).Sum()); else recordList.Add(int.Parse(opt[i])); } return recordList.Sum(); }
@guruswamypunithavathy9785
@guruswamypunithavathy9785 Ай бұрын
My way using stack static string GetSum(List input) { long num = 0;result = 0; if (input.Count
@guruswamypunithavathy9785
@guruswamypunithavathy9785 Ай бұрын
forgot stack declartion Stack puni = new Stack();
@sophieagada8456
@sophieagada8456 2 жыл бұрын
Amazing video
@verxivrmedia
@verxivrmedia 2 жыл бұрын
Glad you think so!
@robertkoifman2549
@robertkoifman2549 Жыл бұрын
I'd like to give you a little better solution ;) public int calPoints(string[] s) { List points = new List(); for (int i = 0; i < s.Length; i++) { if (s[i].Equals("+")) { points.Add(points[points.Count - 2] + points[points.Count-1]); } else if (s[i].Equals("D")) { points.Add(points[points.Count - 1] * 2); } else if (s[i].Equals("C")) { points.RemoveAt(points.Count - 1); } else { points.Add(int.Parse(s[i])); } } int score = 0; foreach (int point in points) score += point; return score; }
@verxivrmedia
@verxivrmedia Жыл бұрын
Thanks so much for this. I'm sure the community would learn from it
@mohammedghabyen721
@mohammedghabyen721 Жыл бұрын
internal void Solution() { Stack stack = new Stack(); for (int i = 0; i < arr.Length; i++) { string cc = arr[i]; if (cc == "C") stack.Pop(); else if (cc == "D") { int peek = stack.Peek(); stack.Push(peek * 2); } else if (cc == "+") { int prevPeek = stack.Pop(); int newNum = prevPeek + stack.Peek(); stack.Push(prevPeek); stack.Push(newNum); } else stack.Push(int.Parse(cc)); } int res = 0; while (stack.Count() > 0) res += stack.Pop(); Console.WriteLine(res); }
@NadirAli-ri7jb
@NadirAli-ri7jb Жыл бұрын
please remove the BG music
@verxivrmedia
@verxivrmedia Жыл бұрын
This is noted. No more background music in upcoming videos
@naveediqbal993
@naveediqbal993 Жыл бұрын
Please remove the background music it really sucks
@verxivrmedia
@verxivrmedia Жыл бұрын
Ok. Thank you so much for the feedback. No more background music in upcoming videos
Ace Virtual Interview: 6 MISTAKES You Need to Avoid
4:53
Turing  Laravel Test Questions
9:49
Simon's Tech School
Рет қаралды 8 М.
Miracle Doctor Saves Blind Girl ❤️
00:59
Alan Chikin Chow
Рет қаралды 21 МЛН
Follow @karina-kola please 🙏🥺
00:21
Andrey Grechka
Рет қаралды 25 МЛН
How the C++ Linker Works
15:52
The Cherno
Рет қаралды 603 М.
PPL One Shot | Unit - 5  | SPPU PPL Series | SPPU | SoloScholar
31:40
Forget about Applying for Jobs on LinkedIn or Indeed and Do This Instead
5:00
KISSS Career Coaching
Рет қаралды 429 М.
Move Semantics in C++
13:10
The Cherno
Рет қаралды 277 М.
How to Ace Turing’s Coding Challenge
42:20
Turing
Рет қаралды 29 М.
Learn C# Sharp in Four Minutes
4:10
Programming w/ Professor Sluiter
Рет қаралды 77 М.
Top 100  C#/ .NET/ Web API/ SQL Interview Questions
2:49:20
Interview Happy
Рет қаралды 483 М.
What Is OpenAI Hiding? | Q-Star OpenAI's Secret Project
7:59
Beyond the veil
Рет қаралды 191