In my opinion, iterating through a collection is very basic and simple thing because it appears in any developer’s code everyday (of course in the languages support collection).

It’s normally my simplest question to start the interview to warmup and make the candidate more confident. But I’m wrong. I’m so surprised that 90% of our candidates, who have been (senior) developers for 2-3 years, cannot give the right answer:

Let say I have a collection LinkedList<int> list. What are differences between 2 types of iterating through list:

and

Most of answer I got is “we can have the index by #1 code that we cannot have in #2 code. The performance are the same.”. But it’s incorrect, #1 is really bad code in performance wise.

The performance are the same in the index-based collection, like array or ArrayList. But #1 code is very slow in other collection like LinkedList. The reason is for getting the item at index i (by calling get(i) method), LinkedList needs to iterate from the first item with the counter set to 0, increase it in each step and stop when the counter reach to i. So while the notation of #1 code is O(N2), the notation of #2 code is O(N).

#2 code actually works as

#3 code is exactly the way #2 code works before Java introduced for each syntax.

The best solution is always use #2 code for iterating through any collection. If you are worry about the index, another code would be:

Java is just a used language here but I believe this way works in any language today. Whatever the technology you are chasing, let start from the basic things, language and data structure.

556 total views, 1 views today

Summer Code Retreat 2015 was organised by Agile Vietnam in August 1st at FPT university, Hanoi. And as normally we did with the Conway’s Game of life.

Some notes from the retrospective sessions by about 30 participants:

1st session

  • There is a communication issue in team
  • We are not familiar with this kind of problem, so spend too much time to find solution
  • The convention was not easy to apply to team

2nd session

  • Solution didn’t work and need to change to another in the end
  • Not good design and spend much time for refactor
  • Would try to use TDD but it didn’t work well

3rd session

  • Got issue with language difference in pair
  • Using rule (no if, no mouse..) seems hard to implement
  • Tried to use recursion instead of loop, it was hard but got a good experience
  • Tried to use TDD, and had the implementation that’s passed 2 test cases at end

4th session

  • Should have good name for a test case (which flow it runs, which is expected result)
  • Using text editor instead of IDE is very difficult
  • Would tried no conditional statements but didn’t work

Final session

  • It’s really fun but challenge when we choose 1 rule and follow
  • Good place, good food, good support
  • Should have more females 🙂
  • I will try to practise more next week

And..

We all know the purpose of Code Retreat that we forget the result-oriented doing by focusing on the on-going experience. Some people was surprised by the first look at some rules, “how we can do programming with conditional statements?”, “how we can make every methods under 8 lines?”… But nothing is impossible :).

No conditional statements? Yes, we can do with polymorphism. You could find it here or here.

No loop statements? Yes, we can do with recursion approach. You could find it here.

Of course, our possibility of implementing the solution without conditional statements doesn’t mean we are good at programming or not, it just shows we have tried with this skill and found a good experience during our implementation.

It’s a reference to Code Retreat, the Conway’s Game of life, and photos of Summer Code Retreat 2015 by Agile Vietnam.

65 total views, no views today

Following my Code Challenge problem Cute girl decoder, here is the solution:

Solution

It seems very easy to solve this problem by replacing the substring such as j by gi, dz by d, k by khong.

But, there is a trick at “With words, she usually use”, that means k should be replace by khong only if it’s a word that is normally separated by these characters: [space] , . ; ? !

You could find an implementation below in Objective-C, my thank to Nghia Luong for the code contribution.

It looks good but in my opinion, we could make it better with the open design.

Better design

Let see my implementation below as I think it could be better design to extend the implementation in the future. But please try to find some area we can improve 🙂

And the decoded message would be:

chan qua. em mun an nhieu ga quay cho doi gio duoc khong day? Anh co phai la nguoi iu cua em khong day, neu a la nguoi ieu cua em thi phai dua em di an ga quay chu, anh ma hem dua em di em gian a lien doa. The gio anh mun nhu the nao? ket qua ha? ok, neu ma anh khong dua iem di an ga ran thi nguoi dung den gap em lam gii nua, em khong yeu anh nua dau, iu gi ma co moi viec dua di an ga quay cung khong duoc thi yeu lam gi day, chan anh vagi dan ra ay. Ngay hom sau em noi gi a, em van noi la: chan qua. em mun an nhieu ga quay cho doi gio duoc khong day? Anh co phai la nguoi iu cua em khong day, neu a la nguoi ieu cua em thi phai dua em di an ga quay chu, anh ma hem dua em di em gian a lien doa. The gio anh mun nhu the nao? ket qua ha? ok, neu ma anh khong dua iem di an ga ran thi nguoi dung den gap em lam gii nua, em khong yeu anh nua dau, iu gi ma co moi viec dua di an ga quay cung khong duoc thi yeu lam gi day, chan anh vagi dan ra ay. Ngay hom sau nua em noi gi a, em noi day ne: chan qua. em mun an nhieu ga quay cho doi gio duoc khong day? Anh co phai la nguoi iu cua em khong day, neu a la nguoi ieu cua em thi phai dua em di an ga quay chu, anh ma hem dua em di em gian a lien doa. The gio anh mun nhu the nao? ket qua ha? ok, neu ma anh khong dua iem di an ga ran thi nguoi dung den gap em lam gii nua, em khong yeu anh nua dau, iu gi ma co moi viec dua di an ga quay cung khong duoc thi yeu lam gi day, chan anh vagi dan ra ay.

Go further

The idea of Skype plugin just came to make this problem more fun. But do you want to make it go live? I didn’t build it yet, but if you like this idea, I would like to code and share in the next post.

Do you want to see the new Skype plugin? Throw me at least 50 likes 🙂

140 total views, no views today

Long had a new girl friend, congrats to him. He feels very happy by chatting with her everyday although it’s not an easy work. As a 9x cute girl, she uses a lot of teenage chatting words and it usually takes Long more time to read and understand. And of course, it takes him a lot of his brain’s energy :).

To make it easy, Long plans to build a Skype plugin that can translate her sentences to the normal ones. He found that it’s so easy to replace the cute words by the following rules:

  • With words, she usually use
    • k for khong
    • ko for khong
    • ng for nguoi
    • n for nhieu
    • dc for duoc
    • hok for khong
    • ntn for nhu the nao
    • kq for ket qua
  • She also use these characters
    • j for gi
    • w for qu
    • f for ph
    • dz for d
    • z for d

So if she says “chan wa. em mun an n ga way cho doi jo dc hok dzay?“, it is “chan qua. em muon an nhieu ga quay cho doi gio duoc khong day?

Could you help Long to write this plugin. After that, please try to translate her recent message:

chan wa. em mun an n ga way cho doi jo dc hok dzay? Anh co phai la ng iu cua em k zay, neu a la ng ieu cua em thi fai dua em di an ga way chu, anh ma hem dua em di em jan a lien doa. The gio anh mun ntn? kq ha? ok, neu ma anh hok dua iem di an ga ran thi ng dung den gap em lam ji nua, em k yeu anh nua dau, iu j ma co moi viec dua di an ga way cung ko duoc thi yeu lam j dzay, chan anh vaj dan ra ay. Ngay hom sau em noi j a, em van noi la: chan wa. em mun an n ga way cho doi jo dc hok dzay? Anh co phai la ng iu cua em k zay, neu a la ng ieu cua em thi fai dua em di an ga way chu, anh ma hem dua em di em jan a lien doa. The gio anh mun ntn? kq ha? ok, neu ma anh hok dua iem di an ga ran thi ng dung den gap em lam ji nua, em k yeu anh nua dau, iu j ma co moi viec dua di an ga way cung ko duoc thi yeu lam j dzay, chan anh vaj dan ra ay. Ngay hom sau nua em noi j a, em noi dzay ne: chan wa. em mun an n ga way cho doi jo dc hok dzay? Anh co phai la ng iu cua em k zay, neu a la ng ieu cua em thi fai dua em di an ga way chu, anh ma hem dua em di em jan a lien doa. The gio anh mun ntn? kq ha? ok, neu ma anh hok dua iem di an ga ran thi ng dung den gap em lam ji nua, em k yeu anh nua dau, iu j ma co moi viec dua di an ga way cung ko duoc thi yeu lam j dzay, chan anh vaj dan ra ay.

The solution will be updated in 3 days.

63 total views, no views today

Do you remember my post about the interview question? It’s one of my problems in our Code Challenge that I would like to share in this post.

Code Challenge is one of our exciting activities last year where we can learn from each other by solving the problems in a contest. I also published the tool on Github for who wants to host this kind of event, please don’t hesitate to contact me if you want to use or need any support.

Purpose

It makes sense, everybody always needs to improve as every organisation needs to go forward. And learning is a good way to keep us improved and motivated. We have thought about the contest that allows every developers join to learn and measure their coding skill, and we held the Code Challenge last year that was involved by all our developers as contestants.

Joining the contest with our colleagues is very fun thing as we can learn from others and see how good we are right now. But it’s not easy for the host because there are various specific platforms or technologies in one organisation or teams, then the contest should target on a shared knowledge or skills in the whole team. To be fair, we should remove all the dependencies that relate to the language or platform uses and back to the basic of software development: programming.

Follow my experience, the ACM ICPC is very good format that focus on the programming but it seems still complex and has language limitation. Project Euler suits us better but it should have the time constraint to identify the winner.

Format

Our Code Challenge is mostly like the Project Euler format with time limitation as ACM ICPC. It was being held bi-weekly in 5 rounds, each round run from 13:00 to 17:00. In 4 hours, the contestants try to solve about 5 or 6 problems by following rules:

  • Solve problems in order. The contestant needs to solve a problem before taking the next one. So the problems should be arranged by their difficulties.
  • Result comparison. It doesn’t matter with the contestants’ solution as they can solve the problem by any programming language (or sometimes by non-programming as by Excel skill). A problem just shows the issue with a specific input data and compare the result with correct solution.
  • Multiple submissions. Contestant can try submit his solution many times as he wants to get the problem solved. The time spend for a problem is that the time he starts the contest to the first attempt of accepted solution.
  • Faster is better, careful is good. The contestants are ranked by these criteria in order:
    • Number of solved problems. The more number of solved problems are, the higher rank of contestant is.
    • Number of submission. If some contestants have the same number of solved problems, the number of submission should be counted. The contestant get higher rank by fewer attempts.
    • Time spend. The time spend should be the last criteria as its precision was counted to millisecond :). It is the total time spend of all solved problems.

Experiences

As our experience, there are some good things we could have from Code Challenge:

  • Fun. It could come from various sources such as a story in problem or the solution. In the 3rd round, we all surprised by a problem can be solved in 3 minutes as it normally takes at least 15 minutes for programming. But it’s so easy to calculate and submit the possible results manually. Yes, he’s so smart.
  • Share and learn. After the contest, we always sit together to share our different solutions of those problems, so we can learn from others and see what was the best way to solve them.
  • Improve. We of course had a good chance to learn from others or from practice during the contest preparation for getting improved.
  • Motivate. Beside the award for winner, there were some secondary awards such as the best newbie, first solved problem, last accepted attempt…etc for our guys trying to get.

And there are a lot of good things you would see as I think you should host at least one Code Challenge in your team.

Issues

Yes, there are various good things we had but in another hand, some minor issues came.

You could see that our format and tool were designed to target the purpose: removing the technology dependencies where contestant can solve the problem by any language (or by non-programming). But the issue is moved to the problem set as we should design them as free-language algorithm – it’s usually not easy. A lot of problems can be solved quickly by Java, C# but much slower in C++ by coding time but versa in running time.

Another issue is that somebody is very good at basic programming and algorithm but someone isn’t. I truly believe that a good developer should be good at algorithm but it seems not work today as the technology goes so far and developer can build the very good products with a normal algorithm background. He of course cannot be bad but doesn’t need to be very strong in algorithm to be a good developer as some years ago because the high-level technologies support us too much. For example, 10 years ago, every good developer needs to know what best sorting algorithm in his case in C++ but today a normal developer doesn’t care about this, just call Sort() method in C# and it would do in the best way. And of course, the results are mostly the same no matter he knows the Sort() method would run by any algorithm. It’s proved in our Code Challenge last year as there was only 1 winner for all rounds. He is very talent and strong in algorithm but isn’t a top guy in product development.

They are just the minor issues we would face in any contest that targets to wide range of developers. The problem content is the best way to resolve these issues but it usually takes much time to create a good problem like that. Contest is not fair but we should keep it as good as possible 🙂

I will share our problems that were used in our Code Challenge last year in some next posts and hope that you can find some interesting things.

And here is the system we have used: https://github.com/hiennvn/code-challenge. It may have some bugs because it just was the first MVP and one of my 24-coding-hours projects. But it worked fine for us last year.

Keep calm and love code.

Don’t want to wait for my next post? Try this problem:

A motor bike plate number is in the format [AB-CD EFG.HI]. Its value is defined by: AB x C + EFG x HI, if C is a letter, its value is its ASCII code. A plate number is called NICE one if its EFG contains its HI, then its value is doubled than normal. Give you a list of place numbers, find the biggest value.

For example: A plate 29-C1 320.12 has value 5783 (= 29*67+320*12)

What is the biggest value of

28-A1 493.68

83-Y3 453.83

17-Z7 439.48

29-C1 292.29

142 total views, no views today

Yes, it’s me – Mr. Coding Tools.

I’m a fan of whatever makes our lives better. Most of them are the tools, right? So someone calls me “Mr. Tools” but it’s not true,  I don’t just use the tools. I’m a Mr. Coding Tools.

What makes a developer different? He can make the amazing tools for on-demand needs of his life, usually are once-use tools. When cannot find an appropriate software for reducing manual work, a rich man can hire people for building it, a normal man needs get back to his boring things in the hopeless, but a normal developer can do it himself. He always feel excited by doing in a smarter way although it sometimes takes more times than doing manually 🙂

When I was 17, the vice president of my mother’s school asked me “I want to show up some texts and photos on the projector board by a cool way in an important meeting next week. They should run from left to right, top to down etc. I have seen it when visiting a conference but I don’t know how to do it on my computer”. So easy with Power Point? Right. But what should you do if you don’t know Power Point? In fact, I had never known Power Point was existing that time. I had my first computer when I was 15 but just used it for programming to solve some algorithm problems or editing with Word to earn more money sometimes. I hadn’t known Internet as well because of its high cost. Borland Pascal, Delphi, Word, NC and FIFA were only my 3rd party softwares I had and known that time – so different when you guys were 17, far ahead from me.

“Yes, you can. Please give me the texts and photos you want to show up and I will get back tomorrow”, I said. What did I do? I wrote a Winform application with some areas for texts and photos, some timer triggers to scroll them in some directions. It was so easy like eating an apple.

“It looks good but could I change the texts and photos myself?”, he said when I got back. “Of course, let do it tomorrow”. And I changed my code for reading texts from files, get a photos from specific folder by their ordered names.

“Yes, it works but could I change the position of these texts and choose the effect myself?”. “Sure, see you tomorrow”. Then I went home, changed my text areas to placeholders and made their positions and sizes  more flexible.

“Super cool, we got it. I can prepare the content for the meeting next week now. How much should I pay?”. “Base on the success of your meeting. Give to my mother, I don’t care”. “Could I use it for the meeting next year?”. “Sure, or next month if you think it would help, otherwise drop it out”.

I believe Agile is in my mindset as long as I know building the software. Iteration, feedback, refactor, minimum viable product etc are so natural and come easily.

2 years later, I laughed out loud at the first time seeing Power Point, “OMG, I reinvented the wheel”. But I was proud of building the useful tool in my limited resource and knowledge. I came back, installed and trained the vice president to use Power Point but he wanted to keep using my tool as he had used it well 7 times for 2 years. Because this tool was enough for his needs and Power Point has too much features but didn’t have Vietnamese user-friendly UI. Simple but enough is better than tons of no-use add-on.

In my career, I has built a lot of tools for myself and see it as the best way to improve both my coding and customer-side thinking skills.

Some days ago, I created a backlog for my next 23 months and I’m thinking about creating a mobile app for tracking as unfortunately I didn’t find any right tool. Again, it maybe a one-use tool.

Sometimes, no tool is better but guru should do build tool.

189 total views, no views today