# LeetCode 55. Jump Game

LeetCode Practice 55.

## Question

A frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.

Given a list of `stones`' positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be `1` unit.

If the frog’s last jump was `k` units, its next jump must…

## Error message

`terminate called after throwing an instance of 'std::system_error'      what():  Resource deadlock avoided`

## Explanation

Two reasons cause this error.

1. The thread owner joins itself.
2. Two threads join each other.

## My code

I utilized the boost io_service to run a heartbeat routine in another thread. It skipped some details in the following code, but you’re still able to see a heartbeat_routine task that would bring a new one.

## So, where is the problem?

Apparently, the heartbeat_routine function takes a weak pointer as arguments. It brought us to the error condition (1. The thread owner joins itself.) when it’s out of the main function which meant…

# C++ get current time(to millisecond)

Sometimes we need t to trace the execution order to make sure the program runs as our expectations, especially the multi-thread programs. We all know ctime is a great function to help us get the current time. It can convert current time to string. But it seems insufficient if you’re handling millisecond cases.

Here we can leverage boost library to acquire subtle time.

Reference:

# 聯發科 C語言測試題目

MediaTek Interview Questions

Okay 上一篇才剛發沒有多久, 趁著還稍微記得題目內容來記錄一下, 希望可以幫到迷途的孩子們

# C語言測試

## 選擇與填充題

• Question 1

keyword: (1) global variable (2) pointers as function arguments

• Question 2

keyword: (1) global variable

• Question 3

keyword: (1) Macro

• Question …

# 聯發科 面試心得分享

MediaTek interview sharing

## Background

• 工作經驗: 兩年
• 擅長程式語言: 專精Python, 略懂C/C++
• 工作領域: Back-end system developement
• 學歷: 洗的四大碩 lol

## Before the interview

1. 去官網填寫個人基本資料, 很重要, 這是面試官在面試前了解你的唯一管道
2. 備妥個人資料(Resume, 學碩成績單, 作品集…)
3. 準備相關的筆試(後續再來發一篇筆試考題好了)
4. 個人有準備面試用的簡報(大概除了碩論以來我準備過最漂亮的一份PowerPoint), 如有準備的同學請提早通知人資單位並請他們準備有投影機的房間

## The interview

1. 筆試14題(C/C++), 包含填充題跟選擇題 & 兩題上機考, 共50分鐘
C語言考蠻多東西, 例如 function pointer, static, global, volitile, macro, C++ template
2. 個人自我介紹(使用精美ppt做簡報), 在過程中盡量把你自己負責過的專案做個簡單扼要的說明, 尤其是你負責的部分, 這很能提起面試官的興趣
這邊我有跟面試官討論一下平行化該怎麼做比較好, 他給了我一個沒想過的答案
3. 面試官提問攻擊, 你負責接下攻擊並反擊, 可能包含了你剛剛報告的內容, 資料結構, 作業系統, 計算機概論… etc.
我個人被問到 dead lock, synchonization, critical section
4. 白 板 題 ! ! ! 面試官看我有記錄一些LeetCode題目在github上, 他就挑了兩題 (1) Are two trees equal (2) Reverse LinkedList
(面試官: 我知道你比較熟Python, 但現在你當然要用C寫)
5. 面試官說明工作內容 & 你的提問時間

2021/4/18

(無聲卡真的讓人不太舒服)

# Hackerrank-Day of the Programmer

Day of the Programmer, Python implementation

# Questions

Marie invented a Time Machine and wants to test it by time-traveling to visit Russia on the Day of the Programmer (the 256th day of the year) during a year in the inclusive range from 1700 to 2700.

From 1700 to 1917, Russia’s official calendar was the Julian calendar; since 1919 they used the Gregorian calendar system. The transition from the Julian to Gregorian calendar system occurred in 1918, when the next day after January 31st was February 14th. …

# Two Characters

Hacker rank — Two characters

LeetCode Record

# Question 1: 243 Shortest Word Distance I

Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.

Note：

You may assume that word1 does not equal to word2, and word1 and word2 are both in the list.

Example:

Assume that words = [“practice”, “makes”, “perfect”, “coding”, “makes”].

Input:word1 = 「coding」, word2 = 「practice」Output:3

Input:word1 = “makes”, word2 = “coding”Output:1

## Thought 3 — Two points

`def getShortest(self, word1, word2)…`

# [Python]“from modulename import *” in Python2 and Python3

Tell you how to use the same code to run in Python 2 and 3.

## Background

After packing my module to wheel, I started to test it and found that the code below couldn’t run in Python 3 but it’s fine in Python 2.

`from modulename import *`

This is the folder structure

`modulename├── __init__.py└── modulename.so`

modulename.so is the file providing functionalities and I needed to wrap some class names as another. The __init__.py is like this:

`from modulename import *ClsPublic = ClsPersonal # export it as ClsPublic`

Then the import error came out. So frustrating!

The fact…

# [Python] mypkg-1.1.0-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.

## Background

I tried to install a wheel package file by pip, but it showed the error.

`\$ pip install dist/mypkg-1.1.0-cp27-cp27mu-linux_x86_64.whl`

I got:

`pyzeal-1.1.0-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.`

## Solution

Renaming the wheel file to fit the supported wheel format. To get the supported format in your environment.

`Python 2.7.11 (default, May  8 2019, 02:10:04)[GCC 5.3.0] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import pip; print(pip.pep425tags.get_supported())[('cp27', 'cp27m', 'manylinux1_x86_64'), ('cp27', 'cp27m', 'linux_x86_64'), ('cp27', 'none', 'manylinux1_x86_64'), ('cp27', 'none', 'linux_x86_64'), ('py2', 'none', 'manylinux1_x86_64'), ('py2', 'none', 'linux_x86_64'), ('cp27', 'none', 'any'), ('cp2', 'none', 'any'), ('py27', 'none', 'any'), ('py2', 'none', 'any'), ('py26'…`

## Jaime Lin

From Taiwan, a beautiful island. Learning English and sharing code experience.

Get the Medium app