---
# System prepended metadata

title: Software Engineer Assessment
tags: [Assessment]

---

# Software Engineer Assessment

###### tags: `Assessment`

> Just play, have fun & enjoy  :brain: :video_game: :rainbow: 

[toc]


##  Logic Questions

1. Before Mt. Everest was discovered, what was the tallest mountain in the world?
**Before Mt. Everest was discovered, the tallest mountain was still Mt. Everest even if no one discovered it.**
2. A cow weighs 800 kilograms, and the weight load of the bridge is 700 kilograms, how does the cow cross the bridge?
**Kill the cow and cut it into 2 then transport 2 times.**
3. What is the largest possible number you can write using only 2 numbers - just 2 numbers, no other mathematical symbols?
**9 to power of 9**
4. There are 3 light bulbs in a hidden room and 3 switches outside the room that correspond to those light bulbs. You do not know which switch affects which bulb and you cannot see inside of the room. You are allowed to go inside of the room only one time. How do you find out which switch corresponds to which bulb?
**If there is 3 switches of A,B,C. turn on A with 30min, B with 5mins. Then after turn off A and B. and can determine the light bulb with which switch according to the temperature of the bulb. Coldest is bulb C, with little heat is bulb B, the most heat is bulb A.**
5. You have two sand timers, which can show 4 minutes and 7 minutes respectively. Use both the sand timers (at a time or one after other or any other combination) and measure a time of 9 minutes.
**Start the sand timers together for both 4mins and 7mins sand timers. Then after the 4mins sand timer finish direct turn the 4mins timer again(so it will be 4+4mins=8). And after 7mins sand timer finish, the previous sand timer will still remaining 1min to continues. So can start the time calculation at this stage. This is due to the request 9mins can be calculate by this remaining 1 mins + 2 turns of 4mins sand timer again.**
6. A snail is at the bottom of a 30 foot well. Every hour the snail is able to climb up 3 feet, then immediately slide back down 2 feet. How many hours does it take for the snail to get out of the well?
**28 hours, (every hour with 1 feet + last hour will climb for 3 feet)**


## Object Oriented Programming Corner

7. What is object-oriented programming?
**Object-Oriented Programming is a programming model that relies on the concept of classes and objects. It help to structure program simple and reusable. There is 4 pillar of object oriented programming which is inheritance, polymorphism, encapsulation and abstraction. 
a.Inheritance is the ability of one object to have the same properties of another object. So those child object can use the attributes of his parent. So it can help to remove redundant code. 
b.Polymorphism is use a class like its parent without confusion on mixing types. Like each child will keep their own function. 
c.Encapsulation is hide the object state without access by other object, other object can only to utilize method provided. 
d.Abstraction is to apply those object without state the step 1 by 1, the object provided/created is already link all the relevant function together.**
8. What are the basic concepts of OOPS.
**The basic concept of OOPS is to create an object that contains data and methods. The advantages of OOPS are fast execution speed, clear program structure, and less structural redundancy. OOPS also helps to eliminate code duplication and make code maintainable. With OOPS, development time can be shortened due to reusability.**
9. What is the difference between class and an object?
**Class is a template that defines all the attributes and function of similar object or entities. but object is an instance from class which is has their own defined properties and behaviours associated with it. Class are merely a concept which is not occupy the memory, but object will allocate memory on the heap.**
10. Write a function that will return 3 possible values, Success, Pending, Failed. Write the code in any language.
```
using System;

public class Program
{
   public static string CheckStatus(string status)
   {
      string result = string.Equals(status, "Success", StringComparison.OrdinalIgnoreCase) ? "Success" : string.Equals(status, "Failed", StringComparison.OrdinalIgnoreCase) ? "Failed" : "Pending";
		  
      return result;
   }

    public static void Main()
    {
        Console.WriteLine(CheckStatus("success"));
        Console.WriteLine(CheckStatus("failed"));
		Console.WriteLine(CheckStatus("pending"));
    }
}

```
11. Initially, write a function that receive a string. At later stage, the same function is required to receive 2 parameters, 1 is number and 1 is DateTime. And later stage the number of parameters may be changed again. Write the snippet for this in the language that you are comfort with.
```
using System;
					
public class Program
{
	public static void Main()
	{
		Processor myProcess = new Processor();
		Console.WriteLine(myProcess.Process("test"));
		Console.WriteLine(myProcess.Process(123,DateTime.Now));
	}
}

class Processor
{
	public string Process(string data)
    {
		string result = data;
        return result;
    }
	public string Process(int data, DateTime datetime)
    {
		string result = Convert.ToString(data) + "|" + Convert.ToString(datetime);
        return result;
    }
}

```
12. Write a function named GetUserSummary that return Name & Age, another function named GetUserDetail that return Name, Age, BirthDate, Gender. Write the code in any language.
```
using System;
					
public class Program
{
	public static void Main()
	{
		UserDetail myUser = new UserDetail();
		myUser.getUserSummary(24,"Chai");
		myUser.getUserDetail(24,"Chai",DateTime.Parse("09/11/1999"),"Male");
	}
}

class User
{
	public int age;
	public string name;
	public void getUserSummary(int age, string name){
	 Console.WriteLine("My name is {0}, and my age is {1}", name,age);
	}
}
class UserDetail : User{
	public DateTime birthDate;
	public string gender;
	public void getUserDetail(int age, string name,DateTime birthDate, string gender){
	 Console.WriteLine("My name is {0} and my age is {1} and birthdate on {2} and I am a {3}", name ,age, birthDate,gender);
	}
}

```
13. Given an array of ints, write a method to total all the values that are even numbers. (Can be any OOP language)
```
using System;
					
public class Program
{
	public static void Main()
	{
        int[] arr = { 2, 3, 4, 5, 6 };
        SumOfEven(arr);
    }
	static void SumOfEven(int[] arr)
    {
        int sum= 0;
        for (int i = 0; i < arr.Length; i++) {
            // checking if a number is
            // completely divisible by 2
            if ((arr[i] % 2) == 0)
                sum+=arr[i];
        }
        Console.WriteLine("Sum of even numeber : {0}",sum);
    }
}

```


## SQL Corner

14. What is the difference between DELETE and TRUNCATE?
**DELETE is Data Manipulation Language command which use to specify the row we want to delete from table. DELETE command can contain WHERE clause that allow to delete only specific rows. DELETE command will show how many row was deleted. Deleted data can be rollback using ROLLBACK command. TRUNCATE is Data Definition Language command which is used to delete all row from table. TRUNCATE command does not contain WHERE clause. The truncate command will not show for deleted data page. TRUNCATE command is fast compare to DELETE command, and we cannot rollback the data after using TRUNCATE command.**
15. What does UNION do? What is the difference between UNION and UNION ALL?
**UNION combine 2 result-set of 2 or more than 2 SELECT statements. UNION will omit duplicate record, UNION ALL will include duplicate record.**
16. What is the difference between IN and EXISTS?
**IN is used when we want to display/select the result-set with some condition that match with list of provided value on certain column(s). EXISTS is a Boolean operator that returns either True or False. It’s used in combination of 2 query, if the subquery return any row, it will return true and show the data according the selected column in main query.**
17. What will be the result of the query below? Explain your answer and provide a version that behaves correctly.
ANSWER
**The result will always be ‘Nope’, this is due to we should not compare using ‘null = null’, because null represent unknown value, so if we want to check is a value whether is empty, we should use IS operator. The correct version should be ‘select case when null IS null then ‘Yup’ else ‘Nope’ end as Result;’**
18. select case when null = null then 'Yup' else 'Nope' end as Result;
19. How do you copy data from one table to another table?
ANSWER
```
INSERT INTO newTable (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM oldTable;

```


## Web Development Questions

20. What’s the difference between GET and POST methods in HTTP requests?
**GET method will carry request parameters with appending URL string, while POST method carry request parameters in message body. So Get request is not secured due to data is exposed in URL, while POST request is secured due to data is not exposed in URL. On the other hand, Get Method is more efficient compare to POST Method.**
21. List out the different ways of CSS code to style below html element highlighted in RED.**
```
<p>This paragraph refers to two classes. </p>
```

ANSWER
Declare in CSS
```
<style>
p { background-color:red; }
</style>
<p>This paragraph refers to two classes. </p>

```
Declare in HTML tag
```
<p style="background-color:red";>This paragraph refers to two classes. </p>
```
22. List out the different ways an HTML element can be accessed in a JavaScript code.
**Get HTML element by Id
Get HTML element by Name
Get HTML element by tagName
Get HTML element by className
Get HTML element by CSS Selector**

23. What would be the result of 2+5+”3” in JavaScript?
73
24. What will be the output when the following code is executed? Explain.
 ```
console.log(false == '0')
console.log(false === '0')
```
ANSWER
console.log(false == '0')
True
, because == operator will convert them same type before comparing, and ‘0’ mean false, so result will be True.

console.log(false === '0')
False, because === operator will check whether 2 operands are equal including checking data type.

25. In what order will the numbers 1-4 be logged to the console when the code below is executed? Why?
```
(function() {
    console.log(1); 
    setTimeout(function(){console.log(2)}, 1000); 
    setTimeout(function(){console.log(3)}, 0); 
    console.log(4);
})();
```
```
1
4
3
2
```
**This is because program will execute the inline code first, so 1 and 4 will be execute first. And due to 2 and 3 will place into event queue and after inline code finish then only execute, and 2 is set timeout of 1 second, so 3 will be show first then only show 2.**
26. What would the following lines of code output to the console? Explain your answer.
```
console.log("0 ||  1 = "+(0 || 1));
console.log("1 || 2 = "+(1 || 2));
console.log("0 && 1 = "+(0 && 1));
console.log("1 && 2 = "+(1 && 2));
```
ANSWER
```
console.log("0 && 1 = "+(0 && 1));
Result
0 && 1 = 0
Explanation： 
A && B returns the value A if A can be coerced into false; otherwise, it returns B. For this case, the first value is false, so return first value.
console.log("1 && 2 = "+(1 && 2));
Result
1 && 2 = 2
Explanation： 
A && B returns the value A if A can be coerced into false; otherwise, it returns B. For this case, the first value is false, so return second value.

```


## Backend 面試題目

## Q27：簡單 JOIN

### 資料表格式說明
- 會員資料表 [Member]：
  - Id：`PRIMARY KEY`
  - Account：會員帳號

- 會員詳細資料資料表 [MemberDetail]：
  - Id：`PRIMARY KEY`
  - MemberId：`[Member]` 的 Id
  - Name：真實姓名
  - PhoneNumber：電話號碼


### 資料表內容：

`[Member]`

| Id | Account |
| ---- | ---- |
| 1 | jack1234 |
| 2 | mark5678 |
| 3 | tom5566 |

`[MemberDetail]`

| Id | MemberId | Name | PhoneNumber |
| ---- | ---- | ---- | ---- |
| 1 | 1 | Jack | 0912345678 |
| 2 | 3 | Tom | 0987654321 |


### 問題：

請寫一段語法，查詢出會員帳號與詳細資訊
需顯示的欄位為：

| Account | Name | PhoneNumber |
| ---- | ---- | ---- |


ANSWER
```
SELECT M.Account, MD.Name, MD.PhoneNumber
FROM Member M
INNER JOIN MemberDetail MD ON M.Id = MD.MemberId
```
## Q28：List 資料更新

### 問題

請處理以下程式中的 `DeleteMembers`：
將傳入 `DeleteMembers` 中的 `members` 做軟刪除
`※ 註：軟刪除就是將 IsDelete 變為 true`
並將已刪除的 member id 轉為 List 回傳
```csharp=
class Program
{
    static void Main(string[] args)
    {
        var members = new List<Member>()
        {
            new Member(1, "Jack"),
            new Member(2, "Mark"),
            new Member(3, "Tom"),
        };
        
        var result = DeleteMembers(members);

        Console.ReadLine();
    }

    /// <summary>
    /// 刪除會員
    /// </summary>
    /// <param name="members"></param>
    /// <returns></returns>
    public static List<int> DeleteMembers(List<Member> members)
    {

        List<int> resultIds = new List<int>();
        
        // ******** 作答區 ********

        // 1. 軟刪除：將 IsDelete 變為 true
        for(int i=0;members.count-1;i++){
            members[i].IsDelete = true;
        }
        // 2. 將已經刪除的會員 id 回傳出來
         for(int i=0;members.count-1;i++){
            resultIds.Add(members[i].Id);
        }
        // ***********************

        return resultIds;
    }

    /// <summary>
    /// 會員
    /// </summary>
    /// <returns></returns>
    public class Member
    {
        public Member(int id, string name)
        {
            Id = id;
            Name = name;
            IsDelete = false;
        }

        /// <summary>
        /// 會員 Id
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 會員名稱
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 是否已刪除
        /// </summary>
        public bool IsDelete { get; set; }
    }
}
```


## Q29. 請回答以下 Console.WriteLine 分別會顯示什麼?
```  C#
namespace Util.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var Tbank = new TaiwanBankAccount();
            var LineBank = new LineBankAccount();

            Console.WriteLine($"1.{Tbank.WithdrawMoney()}");
            Console.WriteLine($"2.{Tbank.BankCode}");
            Console.WriteLine($"3.{LineBank.BankCode}");
            Console.WriteLine($"4.{LineBank.GetMoney(1)}");
            Console.WriteLine($"5.{LineBank.GetMoney(1, 2)}");
            Console.WriteLine($"6.{LineBank.LimitAccount}");
            Console.ReadLine();
        }
    }

    public class BankAccount
    {
        private int LimitAccount = 13;
        public virtual string BankCode => "001";
        public virtual string WithdrawMoney() {
            return "";
        }
        
    }

    public class TaiwanBankAccount : BankAccount
    {
        public override string WithdrawMoney()
        {
            return "Web";
        }
        public override string BankCode => "002";
    }

    public class LineBankAccount : BankAccount
    {
        public override string WithdrawMoney()
        {
            return "Bank";
        }
        public int GetMoney(int amount)
        {
            return amount * 2;
        }
        public int GetMoney(int amount, int amount2)
        {
            return amount * amount2;
        }
    }
}
```
ANSWER
```
Web
002
001
2
2
Unable to access due to private (hit error)
```
## 回答方式
請另開一份 hackmd 記錄下題目以及答案
提供給 HR hackmd 的連結以供審查




