Showing posts with label hackerrank. Show all posts
Showing posts with label hackerrank. Show all posts

Tuesday, June 20, 2017

Hackerrank Solution: Repeated String

Problem Link

Solution Link

Explanation:

This is a simple string manipulation problem. At first, we count the number of a's in the given string and the number is saved in countA variable. We just subtract the number of non- a characters from the string length to find that out. Since we are taking an-length part from an infinite-repeating string, the n-long part will have several occurrences of string s. The variable chunk determines the number of occurrences. So chunk*countA represents the number of a's in chunk number of s strings. We may have a remainder string portion for which we used a separate for loop to count the number of a's there. Last we print out the result.
Runtime: O(n) We used a single loop.

Note: Here n is long type variable because of the constraint 1<=n<=10^12. In Java integer range is -2,147,483,648 to 2,147,483, 647    .And  the range for long is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

so we have chosen a long type variable for n.

You can learn more about Java's variable type ranges from this article by cs-fundamentals.



Monday, June 19, 2017

Beginner's guide: Best Programming Websites for a Novice

There are tons of websites that cater to learning and practicing programming. While some are suitable for beginners, many others are for a bit mature programmers. Here is a list that I use. I recommend these websites to beginner programmers. These are fun, good-looking websites and It won't disappoint you when it comes to guiding you to learn to programme better.


Hackerrank.com :    I have already written a review about this great and fun website in another blog post. Check it out   http://aprogrammersexperience.blogspot.com/2017/05/review-hackerrank-1-great-site-for.html

codeforces.com: It regularly arranges contests where the problems are set by gradual difficulty levels. The problems are later stored in an archive along with their discussions. This is a great website for those who have already learnt the syntax of C, C++ and Java.

codechef.com :   It is also like codeforces with a cute looking interface. But here, the problems come along with subtasks. It means you will receive partial points if the solution passes some of the test cases. This feature is absent in codeforces.com. So I recommend trying out codechef first before proceeding to codeforces.

devskill.com :   This is similar to codeforces but the problems are a little bit easier.

hackerearth.com : This is an interesting website. It has the features of codechef. It also has a fun challenging arena where you duel with another programmer to solve problems as quickly as possible. It regularly arranges various hackathons and idea competitions too. Competing in these hackathons/idea competitions will really broaden your coding horizon.

geeksforgeeks.com: This is not a website for competitions. It is about teaching you about algorithms and their solutions. It is a great guide for your algorithm courses. It explains the solutions of many important, easy and hard algorithms.

tutorialspoint.com: This is a great website to learn a language quickly. They provide numerous examples when explaining an aspect of a programming language. It is your one-stop whenever you need to know something about a programming language. Whenever I find myself confused about syntax or can't remember the syntax I just search through the extensive examples of this website and I am sure to find my answer explained in an easy way.




Monday, May 29, 2017

Hackerrank Review From A Programmer's Experience

Review: Hackerrank

A great site for beginners learning important programming languages and algorithms.  If one signs up and goes to the dashboard page, he/she finds 2 sections - the tracks and the competitions.


The tracks help programmers learn individual programming skills. Each track has its own ranking list to compare oneself to other members. It also contains sub domains which refers to particular sections of a programming skill. These sub domains have their own set of problems. If one keeps solving these problems, the basics of that skill becomes clear since the member here is solving problems and learning a bit of theory as well. The design of these problems is such that the problem acts as an aide to learning the theoretical background. 

In the problem section , the problems are arranged based on their difficulty. There are 4 main difficulties:

  1. Easy
  2. Medium
  3. Hard
  4. Expert 
So the members can choose whatever they find challenging according to their skill level. The beginners are recommended to start from the 'easy' problems and gradually work themselves up to tackle the 'medium', 'hard' and 'expert' problems.



In each problem there's the following panel:

The discussions is a place for open discussion about the problem. The editorial discusses the actual solution. It is accessible after correct submission has been given. 

This is all for today. See you guys later :) 


Interview Questions at Enosis(Part 3)

In Part 2 , I have discussed 3 coding problems out of 6. Here we will talk about the next 3 coding problems. Problem 4: Write a function...