Works Applications interview experience

Works Applications is an Japanese ERP based software company with offices in Japan, Singapore, China, USA and India. Its one of the hottest startup to come out of Japan in the recent years, and their products are used by more than 1/3rd of the whole Japanese companies. They have been existence for more than 10 years and have annual revenues of more than $2.37 trillion!

For the past couple of years, they regualrly visit colleges like IITs, NITs, IIITs, BITS, UOH and various other universities, and recruits around 50 students from the whole of India for their Singapore office. They pay a fixed handsome annual package of 6,000,000 JPY! If you are good with programming, I would recommend you to apply. They do not even have any eligibility criteria! I shall be detailing my interview experience with them, without revealing too much about the interview process.

If Works Applications will visit your college, you can apply on-campus. If not, check out their Facebook page, and register offcampus when recruitemt in India starts. Even though Works Applications visits my college, I registered online when recruitment in India started. I received an email from them saying that I shall receive more details when their recruitment schedule is fixed. After a couple of weeks I received another email detailing their recruitment process.

There was an initial coding test which I needed to pass to get selected for interviews. This coding test was to be conducted in 4 weeks, and I could select any one of the week to do the test. I choose one of the week for my coding test, and when the week arrived, I received my test. There were 2 questions, which were to be solved using either C++ or Java in 5 days. I coded my solution and submitted it online. One thing to remember is that you are competiting again the whole of India, and hence your programs should run as fast as possible, even in the worst case. As far as I’m concerned, this was the hardest stage to clear.

I didn’t hear anything from them for a couple of weeks. Meanwhile, they also visited my college and conducted the coding test. Since I had submitted my test earlier, I was not eligible for further tests. Another few weeks passed by, and one day I received an email from them congratulating me for getting selected for interviews, and asking me to schedule my interviews. I had heard that they shall reimburse your expenses in getting to the interview locations, but since my interview location was so close to me, there wasn’t any need of reimbursement for me.

My interviews were scheduled for 10 in the morning, but I was already at the location by 9. I was asked to submit my resume. At 10, my first live coding round started. I introduced myself and gave some details regarding my internship experience and the projects I had done. The interviewer then gave me my first question. It was a modification of the code I had submitted online. I was given a computer to code my solution, and the interviewer was watching every line I type through another computer. It was quite a simple program and I completed it with ease. The interviewer then gave my second question. I started off with a bruteforce approach and then optimized it later. Once my 45 minutes were up, I was asked to wait.

Later I was informed that I had passed the interview and shall soon have my second live coding round. Meanwhile more and more students were coming and having their interviews. In my second live coding round, me and my interviewer got into a nice chat. We talked about Japanese and Indian cultures, and about the cultural diversity in their offices along with its pros and cons! The interviewer then gave me a problem to solve. It wasn’t much diffcult and I again solved it with ease. The interviewer then asked me to check for edge cases, and I had missed one! I edited my program to fix it. Interviewer seemed satisfied with my solution, and asked me to wait.

Later I was informed that I had passed the interview and shall be having an aptitude test soon. I had 30 questions to be solved in 50 minutes. If you have ample experience in solving basic maths and quant-like questions, this test shall be quite easy. It was easy for me too, and I was informed later that I had passed the test and shall have the HR interview soon.

During the HR interview, I was asked some typical HR questions and we had a nice chat about Works Applications and what they do. (To those who wish to appear for Works Applications interviews, I would recommend you to learn a bit about the company and their products. It would help in having a smooth interview). We also talked a bit about the Indian and Japanese cultures. At the end of the interview, the HR manager congratulated me and handed me my offer letter! Yes! I got selected into Works Applications.

Why is size of int in most 64-bit systems 4 bytes?

I had written an extensive post detailing why size of int is not fixed and what C standard says about it. Have a look through it.

If you lack a basic understanding of the sizes of various data types, I suggest you take a look at: http://programmingbytes.tumblr.com/post/124121068726/what-is-sizeof-int

There are currently 5 main data models:

  • LP64
  • ILP64
  • LLP64
  • ILP32
  • LP32

Datatype LP64 ILP64 LLP64 ILP32 LP32
char                8        8          8        8        8
short             16      16        16      16      16
int                 32      64        32      32      16
long              64      64        32      32      32
long long                            64
pointer          64      64        64      32      32

Depending on the data model used by your compiler, the size of primitive data types shall vary.

Have a read through: http://www.unix.org/version2/whatsnew/lp64_wp.html

What is the size of int in C?

Your C textbook might say sizeof(int) = 2, and another might say its 4 actually! Quite confusing, and yet both are wrong. If your textbook say its either 2, 4 or something else, its either old or wrong! One way or the other, its time to look for a new book!

The C standard mentions nothing about the size of int or other primitive data types. All it does mention is a range of integers it can hold, and in case of int, -32768 to 32767, which requires 16 bits or 2 bytes minimum.

The keyword here is minimum. Int should be able to hold atleast any numbers within -32768 to 32767, or should be 2 bytes in size minimum. But compilers are free to go beyond that minimum. On 32-bit and most 64-bit systems, you shall see sizeof(int) = 4.

Lets write a simple C program.

#include <stdio.h>

int main() {

    printf(”Sizeof int = %d\n”, sizeof(int));

    printf(”Sizeof int* = %d\n”, sizeof(int*));

    return 0;

}

In 16-bit systems, sizeof int shall probably be 16 bits or 2 bytes. On 32-bit systems, sizeof int shall probably be 32 bits or 4 bytes. But when you run it on 64-bit systems, you might be expecting 64 bits or 8 bytes due to the word size. But chances are, sizeof int in 64 bit systems shall still be 4 bytes.

The interesting thing to note here is sizeof(int*), which is same as the word size of your processor. On 64-bit systems, sizeof(int*) = 8 bytes, and on 32-bit systems, its 4 bytes.

Another thing worth mentioning is about sizeof(long) and sizeof(short). On your system, sizeof(int), sizeof(long), sizeof(short) might have the same value. All C standard mentions is the range of values:

short: -32768 to 32767

int: -32768 to 32767

long: 2147483648 to 2147483647

All the above are signed values. Since short, int, long can be held in a 4 byte memory, chances are sizeof int, short, long shall be 4 bytes (if you are having a 64 bit system).

A couple of things to remember:

  • A short int must not be larger than an int.
  • An int must not be larger than a long int.
  • A short int must be at least 16 bits long.
  • An int must be at least 16 bits long.
  • A long int must be at least 32 bits long.
  • A long long int must be at least 64 bits long.

if you need to understand why compilers choose these sizes, have a look though: http://www.unix.org/version2/whatsnew/lp64_wp.html

But sizeof(char) is fixed and is 1 byte. If you need bigger width char types, have a look at the wide character data type – wchar_t.

To fix this discrepancy, C99 introduced some fixed width integers like int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t. They are defined in <stdint.h>. Irrespective of the compiler or the machine you use, their size is fixed. Just don’t forget to turn on the C99 mode!

Deploying your PHP app to Heroku

You have started learning web designing and development. You have designed your first web app. Voila! But contrary to mobile apps, you need to host your web app on some server so that you can show off your impressive web app to others. Shelling out $5 a month on shared hosting for your first app doesn’t sound like a good idea. Enter Heroku!

Heroku is a PaaS, and if my memory serves me right, it may be the first PaaS offering too. For your first PHP app, Heroku may sound like a good option. With 512MB of RAM, 2TB bandwidth/month, and plenty more features, you wont have to think beyond Heroku. But even though most of its features are documented, you probably shall find less support for PHP from the open source community.

Though deploying your first PHP app on Heroku may sounds like child’s play, activating most of the features like gzip, caching static assets, setting expiry headers are quite a herculean task for someone quite inexperienced in this field. For someone well versed in Linux, git and compiling Apache and PHP from source, Heroku shall present itself as the best hosting option.

  1. Signup for a Heroku account
  2. Download and install Heroku Toolbelt. Git is already bundled along with it.
  3. Open up your command prompt, and navigate to your app folder using the cd command
  4. Login to Heroku, using heroku login. Enter your email address and password, and you shall be authenticated. Once you login, you need to create a ssh key.
  5. Once you complete that, type git init. It shall initialize your app folder with an empty git repo.
  6. Type git add .
  7. Type heroku create appname. Change appname to any name of your choice. If you want some random name, use the command heroku create
  8. Type git commit -m “Initial commit”
  9. Type git push heroku master

If you dont have an index.php file, it shall give an error. So better have an index.php in the root. With that, you have deployed your first PHP app!

Why doesn’t C support function overloading?

I have heard this question over and over – Why doesn’t C support function overloading? Rather than quoting C standard back to you, I thought I shall take a practical approach.

Let’s write a simple C program.

#include <stdio.h>

void func() {

    printf(”Hello World!\n”);

}

int main() {

    func();

    return 0;

}

Compile it, and get the binary. Those who are familiar with Linux, shall know the nm command. Lets apply that on the binary, and we get the below output.

0000000000601040 B __bss_start
0000000000601040 b completed.6335
0000000000601030 D __data_start
0000000000601030 W data_start
00000000004004a0 t deregister_tm_clones
0000000000400510 t __do_global_dtors_aux
0000000000600e08 t __do_global_dtors_aux_fini_array_entry
0000000000601038 D __dso_handle
0000000000600e18 d _DYNAMIC
0000000000601040 D _edata
0000000000601048 B _end
0000000000400604 T _fini
0000000000400530 t frame_dummy
0000000000600e00 t __frame_dummy_init_array_entry
0000000000400768 r __FRAME_END__
000000000040055d T func
0000000000601000 d _GLOBAL_OFFSET_TABLE_
                w __gmon_start__
0000000000400408 T _init
0000000000600e08 t __init_array_end
0000000000600e00 t __init_array_start
0000000000400610 R _IO_stdin_used
                w _ITM_deregisterTMCloneTable
                w _ITM_registerTMCloneTable
0000000000600e10 d __JCR_END__
0000000000600e10 d __JCR_LIST__
                w _Jv_RegisterClasses
0000000000400600 T __libc_csu_fini
0000000000400590 T __libc_csu_init
                U __libc_start_main@@GLIBC_2.2.5
000000000040056d T main
                U puts@@GLIBC_2.2.5
00000000004004d0 t register_tm_clones
0000000000400470 T _start
0000000000601040 D __TMC_END__

Please keep in mind that it can vary with compiler.

If you look through the above output, you shall see the func function.

Now, let’s compile the same program using G++ compiler, and apply the nm command on the new binary.

0000000000601040 B __bss_start
0000000000601040 b completed.6335
0000000000601030 D __data_start
0000000000601030 W data_start
0000000000400560 t deregister_tm_clones
00000000004005d0 t __do_global_dtors_aux
0000000000600dd8 t __do_global_dtors_aux_fini_array_entry
0000000000601038 D __dso_handle
0000000000600de8 d _DYNAMIC
0000000000601040 D _edata
0000000000601048 B _end
00000000004006b4 T _fini
00000000004005f0 t frame_dummy
0000000000600dd0 t __frame_dummy_init_array_entry
0000000000400818 r __FRAME_END__
0000000000601000 d _GLOBAL_OFFSET_TABLE_
                w __gmon_start__
00000000004004d0 T _init
0000000000600dd8 t __init_array_end
0000000000600dd0 t __init_array_start
00000000004006c0 R _IO_stdin_used
                w _ITM_deregisterTMCloneTable
                w _ITM_registerTMCloneTable
0000000000600de0 d __JCR_END__
0000000000600de0 d __JCR_LIST__
                w _Jv_RegisterClasses
00000000004006b0 T __libc_csu_fini
0000000000400640 T __libc_csu_init
                U __libc_start_main@@GLIBC_2.2.5
000000000040062d T main
                U puts@@GLIBC_2.2.5
0000000000400590 t register_tm_clones
0000000000400530 T _start
0000000000601040 D __TMC_END__
000000000040061d T _Z4funcv

There is no func function! What happened really is that the G++ compiler changed the name of func symbol to _Z4funcv! So when you overload your functions in your C++ code, even though they have the same name in the source code, they have different symbol names in the binary. Its called name mangling.

So if you write a C++ code having a func() function, make it into a library, and try calling it from C, you shall get a “undefined reference to func()”. The reason being that in the C++ library, instead of func, its _Z4funcv. But you can solve this issue by putting the C++ code inside “extern C” block.

#include

extern “C” {

    void func() {

        printf(”Hello World!\n”);

    }

}

int main() {

    func();

    return 0;

}

Lets compile it using G++ compiler and see the nm output.

0000000000601040 B __bss_start
0000000000601040 b completed.6335
0000000000601030 D __data_start
0000000000601030 W data_start
0000000000400560 t deregister_tm_clones
00000000004005d0 t __do_global_dtors_aux
0000000000600dd8 t __do_global_dtors_aux_fini_array_entry
0000000000601038 D __dso_handle
0000000000600de8 d _DYNAMIC
0000000000601040 D _edata
0000000000601048 B _end
00000000004006b4 T _fini
00000000004005f0 t frame_dummy
0000000000600dd0 t __frame_dummy_init_array_entry
0000000000400818 r __FRAME_END__
000000000040061d T func
0000000000601000 d _GLOBAL_OFFSET_TABLE_
                w __gmon_start__
00000000004004d0 T _init
0000000000600dd8 t __init_array_end
0000000000600dd0 t __init_array_start
00000000004006c0 R _IO_stdin_used
                w _ITM_deregisterTMCloneTable
                w _ITM_registerTMCloneTable
0000000000600de0 d __JCR_END__
0000000000600de0 d __JCR_LIST__
                w _Jv_RegisterClasses
00000000004006b0 T __libc_csu_fini
0000000000400640 T __libc_csu_init
                U __libc_start_main@@GLIBC_2.2.5
000000000040062d T main
                U puts@@GLIBC_2.2.5
0000000000400590 t register_tm_clones
0000000000400530 T _start
0000000000601040 D __TMC_END__

Yes! We now have the func symbol in the binary! We can now make it into a C++ library and shall have no problem calling it from C code.

Any function declared/defined within extern C block shall have C linkage, meaning that you can’t have overloaded functions within extern C block (hope you can figure that out yourselves!)

If you look through some C++ libraries, you shall see code like the below.

#ifdef __cplusplus

    extern “C” {

#endif

// All functions declared here.

#ifdef __cplusplus

    }

#endif

__cplusplus macro is defined by every C++ compiler, and hence the “extern C” block shall become visible only when compiled using a C++ compiler.

The interesting fact is that C++ standard doesn’t mention how the name mangling should be done or what algorithm to follow. Its left entirely upto the compiler designers.

Why local variables in C have garbage values as default?

Local variables are those variables that are created within a function. Unless its static, they go out of scope and are destroyed when the function finishes its execution. All local variables are stored in the stack. I hope you know what a stack is. Before a function begins execution, details like function arguments, return address, local variables, etc is pushed onto the stack. When the function finishes execution, its popped off the stack.

Consider the below program.

int f1() {

    f2();

    f3();

}

int f2() {

    int a = 10;

}

int f3() {

    int b;

    printf(“%d\n”, b);

}

If you run the above program, you might get output as 10 (It might vary depending on your stack structure). On first look, it looks like garbage value, but its actually the value of a in function f2(). You can change the value of a, but the output shall still be the value of a. That should be enough to tell you that its not “garbage value” like most people would call it.

Let’s go deep. First f1 gets called, and is pushed onto the stack. F1 calls f2, and f2 is pushed onto the stack. The stack now contains f2 and f1. After f2 finishes its execution, its popped off the stack. Now f1 calls f3, and f3 is pushed onto the stack. The stack now contains f3 and f1. But f3 is stored in the exact location of where f2 was stored earlier. Since the memory is not cleared before pushing f3, we get what we call “garbage value”, which is actually the data used for f2.

Segmentation Fault – Why does it occur?

int main() {

    int *a = NULL;

    printf(“Value of a = %d\n”, *a);

    return 0;

}

Those who are proficient in C can easily notice that the above C code shall result in Segmentation Fault. And the reason? Derefering a NULL pointer

For the less savy person, a is a pointer with value NULL. A pointer stores the address of some variable, which means that the value of a pointer is address of some variable. Here a is storing NULL, which means its pointing to nothing. In the next line, we use the * or dereferencing operator. What it does is that, it tries to get the value of the variable to which a is pointing. For example, if a has the address of b, then *a gives the value of b. But in this example, a is storing NULL, which in most Operating Systems mean the address 0x0. Since we cant access that address, we cant get the value from that address. Segmentation Fault.

Unlike Java which shall throw NullPointerException, in C or C++, Segmentation Fault is not easy to detect until and unless you start learning how to use a debugger like GDB. You won’t get any helpful messages to help you debug the point of issue.

A segmentation fault occurs due to an invalid access to a memory location. In other words, you are trying to access some memory location for which you do not have access or not allowed to. Another example is, you create an array A[10]. If you try accessing the A[10] or A[11] element, it can result in a segmentation fault. The keyword here is “can”. Its not necessary that a segmentation fault should occur, since C does no bound checking. So if you can access A[10] memory address, it shall give you the value stored in that address.

Segmentation Fault cannot be avoided. Every single C programmer shall be greeted with Segmentation Fault at one or another point in their career. The only way forward is to understand why it happens. It may be as simple as missing out a ‘&‘ in a scanf() statement. Learn to use GDB or some other debugging tool. In all probability, the errors shall be so simple that you shall understand the error once you see the backtrace.