Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,217,562 members, 8,034,650 topics. Date: Sunday, 22 December 2024 at 08:00 AM

The Weekend Algorithm - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / The Weekend Algorithm (1245 Views)

Thread For Nairaland Algorithm Questions / Nigerian Developers How Did You Master Algorithm And Problem Solving / Simple Algorithm Exercise (2) (3) (4)

(1) (Reply) (Go Down)

The Weekend Algorithm by Yungmakaveli01(m): 8:37pm On Aug 05, 2023
Hello everyone I came up with a series titled the weekend algorithm.

It is a series that involves solving some programming questions on different scale of difficulty level and posting them every weekend on the iocode youtube channel, hence the reason for title (Weekend Algorithm).

see the link to the channel https://www.youtube.com/@IOCodes

I've a free course introduction to programming course coming up on the 14 of this month so do reach out to me on whatsapp @(zero7zero524seven2four06) me if you are interested.
Re: The Weekend Algorithm by Yungmakaveli01(m): 8:38pm On Aug 05, 2023
Now the first problem we'll be solving in this series is title the Tram Array

[b]Problem/b]

A city has N Tram stations numbered from 1 to N that are connected to one another and form a circle. You are given an array ticket_cost where ticket_cost[i] is the cost of a ticket between the stops number i and (i + 1) % N. The Tram can travel in both directions i.e. clockwise and anti-clockwise.

Return the minimum cost to travel between the given start and finish station.

You are given an integer N where N represents the total number of the tram stations, an integer start which represents the start station, and an integer finish which represents the finish station. You are given an array of positive integers ticket_cost where ticket_cost[i] represents the ticket cost between the station number i and (i + 1) % N. and you are to determine the minimum cost it takes to travel between the given start and finish position

Example

Assumptions

N = 4
start = 1
finish = 4
ticket_cost = [1, 2, 2, 4 ]
Approach

path1 -> 1------1-----> 2 -------2------> 3 -------2------> 4 . => 1+2+2 => 5

path2 -> 1------4------>4 . => 4

Path2 will give the minimum cost. Therefore return 4.


Question is credited to hackerearth.

see the algorithm I used in solving the given task.

https://www.youtube.com/watch?v=HzeWxbv5s7k

1 Like

Re: The Weekend Algorithm by Yungmakaveli01(m): 1:50am On Aug 16, 2023
It is here again though it didn't come on a weekend.

In last week video of the weekend algorithm I looked at a question gotten from
hackerearth that was about a binary number series without consecutive 1s.
The question goes like this

You are given a set of binary elements. You have to eliminate the binary numbers that contain 11 as a substring. The resultant sequence will be 1, 10, 100, 101, 1000, and so on.

You are required to generate the code to determine the Kth value of the new sequence.

Input format:-
First line: T denoting the number of test cases
Next T lines: a single integer K

Output format:-
Print T lines representing the code to display the Kth value of the sequence.

Sample input
number of test cases = 2
K-1 = 3
K-2 = 9

Sample output
100 for K = 3
10001 for K = 9
see full video showing how I came up with an algorithm that solves the problem

https://www.youtube.com/watch?v=hPAVWSMEpBk
Re: The Weekend Algorithm by Yungmakaveli01(m): 2:06am On Aug 16, 2023
I've a free course coming soon it is an Introduction to programming using Java starting on the 20th of August and
ending on the 11th of September so if you feel interested or might have friends that are interested in learning programming, you can share this info with them.
you can checkout my facebook page and join the telegram group chat on the iocode profile bio
https://web.facebook.com/codes.io/ as that is where I'll be posting relevant updates concering the course
Re: The Weekend Algorithm by LikeAking: 1:57pm On Aug 18, 2023
Nice!

Also post your solutions here!
Re: The Weekend Algorithm by Yungmakaveli01(m): 5:04pm On Aug 19, 2023
LikeAking:
Nice!

Also post your solutions here!
Okay I'll do that in my next video.
Re: The Weekend Algorithm by Yungmakaveli01(m): 5:25pm On Aug 20, 2023
In todays video on the weekend algorithm I showed how I came up with a particular algorithm that solved a problem from Hackerearth that has only 29% success rate so far.

The question goes like this.

Problem
You are given a permutation with length n. You want to play a game with you friend, Bob, and the rule will be as follows:

You will choose a subarray of range [l-r] from the permutation. Then, ask Bob to find the maximum element in the rest of the numbers.
You are given a permutation a contains all numbers 1 to n. And, in q queries, each query has two integers l and r.

For each query, you have to help Bob find the maximum value that does not exist in the subarray of range [l-r] from the original array.

Note: A permutation is a sequence of integers from 1 to n of length n containing each number exactly once.
For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations and (1, 1), (4, 3, 1), (2, 3, 4) are not.

Input format

The first line contains two integers n and q denoting the number of elements and the number of test cases.
The second line contains n space-separated integers.
The next q lines and each line contains two integers l, r.

Output format:
Print the maximum number that does not exist in the subarray .

Sample Input:
5 3
2 3 1 5 4
1 2
2 4
2 5

Sample Output:
5
4
2

Time Limit: 2s
Memory Limit: 256
Source Limit:
Explanation
In the sample, we have a permutation (2, 3, 1, 5, 4)

the first test-case [l,r] = [1,2] so we have to find the maximum number of the array except for the subarray [1,2]

in other words, we have to find the maximum number for the subarray [3,5] which will be 5

video solution

https://www.youtube.com/watch?v=2vgDKVrcFqg

would be updating the thread during the week to post the algorithm.
Re: The Weekend Algorithm by Yungmakaveli01(m): 9:39am On Oct 08, 2023
I'm back, for sometime now I've been quite busy with a project and was also preparing for an interview with Turing,
So I was unable to create any content all through this period.
Re: The Weekend Algorithm by Yungmakaveli01(m): 9:54am On Oct 08, 2023
Searching is a very important concept in programming and with the
numbers of data on the internet increasing over the years the
came different types of searching algorithm.


Linear search is the very basic of all the different searching algorithm there is.
It involves checking every particular element in a given list in a sequential order i.e one after the order,
starting with the very first item until it gets to the given item that is been searched for.

In today's episode of the weekend algorithm the problem we looked at is known as
'Find Mex' and to arrive at a solution that solves the problem Linear search came into the picture.
check the video below to see how the problem was solved.


https://www.youtube.com/watch?v=CbEnG0j_hOo

Problem

You are given an integer array of length N. You have to find the mex of 'ith' item element for all 1 <= i <= N.
The of the 'ith' element is the minimum element greater than or equal to 0 which is not present in array till the 'ith' index.

Algorithm

Re: The Weekend Algorithm by Yungmakaveli01(m): 11:45pm On Oct 22, 2023
Linear Search is a term that is used in a situation whereby items inside a list are been searched for in a sequential manner one after another without skippin anything in between. This concept is a powerful concept that is even employed in the use of Computer Program and even in most cases our normal daily activities. Checkout the video below to see how a particular problem gotten from the hackerearth was solved using Linear Search. #Java #Algorithm #Linear_search



https://www.youtube.com/watch?v=2u1vswdigQ0
Re: The Weekend Algorithm by Yungmakaveli01(m): 11:54pm On Oct 28, 2023
A new weekend, a new algorithm...

The drill remains the same, The problem, the algorithm and the solution.

In todays episode of the weekend algorithm we take a look at a problem that has to do with archers and their respective targets
and how this particular problem implemented an algorithm that made use of the very known mathematical called the Lowest common multiple also known as LCM for short, to solve the problem....

#Question Of The Day
N archers are shooting arrows at targets. There are infinite targets numbered starting with 1. The i-th archer shoots at all targets that are multiples of k-ith.

Find the smallest target that is hit by all the archers.


# Input
The first line contains an integer T - the total no. of testc ases.

T test cases follow. Each test case is of the following format:

The first line contains a natural number - N - the number of archers. The second line contains N space-separated integers, where the i-th integer denotes the value of k for the i-th archer.

# Output
For each test case, print the smallest target that is hit by all archers on a new line.

# Sample Input
1
3
2 3 4
# Sample Output
12

# Explanation

The first archer shoots at targets 2, 4, 6, 8, 10, 12, 14, ...

The second archer shoots at targets 3, 6, 9, 12, ...

The third archer shoots at targets 4, 8, 12, 16, 20, ...

The smallest target at which all archers shoot is .


https://www.youtube.com/watch?v=PNFHB8jRhkM

(1) (Reply)

Dear Programmers, Win N3.25million In The Google App Developers Challenge 2012 / How Do You See This New Website Idea? / National Developer Survey

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.