# of reference frames in various video codecs



AVC allows up to 16 reference frames to be used, but in practice, it
is rare to use more than 5.


From x265 manual https://x265.readthedocs.io/en/2.5/cli.html#cmdoption-ref

— ref <1..16>
Max number of L0 references to be allowed. This number has a linear multiplier effect on the amount of work performed in motion search, but will generally have a beneficial affect on compression and distortion.

Note that x265 allows up to 16 L0 references but the HEVC specification only allows a maximum of 8 total reference frames.
- if you have B frames…


Example 1:

Input: s = "babad"
Output: "bab"
Note: "aba" is also a valid answer.

Example 2:

Input: s = "cbbd"
Output: "bb"

Example 3:

Input: s = "a"


C++ stl container is very convenient for this problem

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key’s value at a certain timestamp.

Implement the TimeMap class:

  • TimeMap() Initializes the object of the data structure.
  • void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp.
  • String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp. If there are multiple such values, it returns the value associated with…

linux signal hander

#include <signal.h>
#include <unistd.h> // for STDOUT_FILENO
#include <stdio.h>
void handler(int num) {
write(STDOUT_FILENO, "refuse to die\n", 13);
int main() {
// with…


strings executablereadelf -symbols executableobjdump -t executable // symbol tableobjdump -s executable // different sectionsobjdump -d executable // disassemblereadelf --segments ./test.elfsegments: segment of memory

shim layer for library

Simple replacement layer that replace gnu library


// test.cpp
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
for (int i=0; i<5; i++) {
printf("%d: %d\n", i, rand());
return 0;

Shim layer for rand()

// shim.cpp
extern "C" {
int rand();
int rand() {
return 888;


CFLAGS=-Wall -g
BINS=test.elf shim.so
all: $(BINS)%.so: %.cpp
$(CC) $(CFLAGS) -fPIC -shared -o $@ $^
%.elf: %.cpp
$(CC) $(CFLAGS) -o $@ $^
rm $(BINS)
rm -r *.so


$ make
g++ -Wall -g -o test.elf test.cpp
g++ -Wall -g -fPIC -shared -o shim.so shim.cpp
$ LD_PRELOAD=./shim.so ./test.elf
0: 888

C++ linux


#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h> // for dlopen, dlsym, dlclose
int main(int argc, char** argv) {
if (argc < 3) {
printf("usage: %s <library> <number>\n", argv[0]);
char* libPath = argv[1];
int number = atoi(argv[2]);
void* libHandle = dlopen(libPath, RTLD_LAZY);
if (libHandle == nullptr) {
perror("dlopen failed");
typedef int (*func)(int);
func f;
f = (func)dlsym(libHandle, "perform");
if (f == nullptr) {
perror("dlsym failed");
printf("%d --> %d\n", number, f(number));
return 0;


extern "C" {
// C++ mangles function name. …


Given a rows x cols screen and a sentence represented as a list of strings, return the number of times the given sentence can be fitted on the screen.

The order of words in the sentence must remain unchanged, and a word cannot be split into two lines. A single space must separate two consecutive words in a line.

Example 1:

Input: sentence = ["hello","world"], rows = 2, cols = 8
Output: 1
The character '-' signifies an empty space on the screen.

Example 2:

Input: sentence = ["a", "bcd", "e"], rows = 3, cols =…

Poby’s Home

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store