Photo by Math on Unsplash

When it comes to implement algorithms that deals with strings, I often use two methods in Java String class: charAt() and toCharArray().

They both can perform some of the same functionalities, e.g. loop through each character in a string. Personally I’m a fan of toCharArray() as I can write more compact code and it saves me a lot of typing, especially in more complex logic. Here is a silly example:

void foo(String bar) {
for(char c : bar.toCharArray()) {

Instead if I re-write the same function using charAt(), it would be something like below:

void foo(String bar)…

In this question, we are asked to write a routine to convert an Arabic integer number (I’ll use number to save some typing) into Roman numerals.

To better understand how a number can be represented in Roman numerals, I created below chart:

From above chart, we can observe below patterns:

  1. unit of each place is represented with a distinct symbol, e.g. ‘I’ for ones place, ‘X’ for tens place, ‘C’ for hundreds place, etc.
  2. number 5 in each place is also represented with a distinct symbol, e.g. 5 in ones place is ‘V’, 5 in tens place is ‘L’, etc.

In this question, we are given an array of integer nums and an integer target, and we are asked to return two distinct indices such that the numbers in those positions add up to be the target. The question assumes that there is one and only one solution for each input.

Approach 1: Brute Force

Traverse the array. For each number num in the array, traverse the rest of the array to see if target - num can be found.

For example:

Java implementation:

For time complexity, let n be the length of the integer array. In the outer loop, we traverse each…


Using var declares either a locally(within function) scoped variable or a globally scoped variable.


When var is used outside a function, it declares a globally scoped variable.

var a = 2; // globally scoped variablefunction foo() {
foo(); // prints out 2console.log(window.a); // prints out 2

This is similar to adding a property to window object directly, while there is a difference: you can’t delete the variable declared using var.

var a = 2; // globally scoped variablewindow.b = 3; // new property of window object, also globally scopeddelete a; // returns falsedelete…

In today’s Executive Order on Addressing the Threat Posed by WeChat, WeChat is gonna to be banned in 45 days. In this story I will talk about what will, probably, happen to the WeChat users who are currently residing in the States after it is banned?

I’m an international student from China currently pursuing my master’s degree in the States and I’m also a heavy user of WeChat. Everyday I text my friends and family in China using WeChat. I also text most of the Chinese international students here with it.

It’s really hard to imagine the life without WeChat…

Typically you can invoke your API using a URL of the following format after deploying:

Even though the region and stage are relatively stable and easy to remember, the api-id is kinda like a random number for each API created and is really not user friendly when it comes to memorizing. It would be great if we can invoke the API using a custom domain name, for example:

or something like

I have an API Gateway API which triggers a Lambda function to serve Gatsby site and backend APIs and a domain registered with Route53. My goal…

Deploying a multi-page Gatsby app to Lambda can be tricky, as you may find that the root URL works fine, while it breaks as soon as you click on some internal link trying to navigate to a different page within your app.

In this article, I will demonstrate how to deploy a multi-page Gatsby app to Lambda with the help of serverless, serverless-http and Express.js.

Create a Gatsby Site

For the demonstration purpose, I’ll use one of the Gatsby official starter — gatsby-starter-blog-theme. You can also use whatever Gatsby project you have at hand.

  1. Breate a Gatsby site with gatsby-starter-blog-theme:
# create a new…

I’m currently working on an API website that provides users with APIs to retrieve movie information in JSON format. The very first challenge I met when designing the overall architecture was how can I serve my front-end web pages together with backend APIs under the same URL, i.e. if a user enters

the server will return the website home page so user can signup for a free API key/ browse document to learn how to use the API; if a user enters

the server will return corresponding JSON data/error message based on the query strings user supplies.


Connecting to DynamoDB from Lambda is even easier than you can think of.

Firstly, you need to create an execution role which later you can attach to the lambda function. To do so:

  1. Login IAM, select Roles under Access management in the left sidebar, click on the Create role button.
  2. In the Select type of trusted entity section, select AWS service and select Lambda in the Choose a use case section.

3. Select a policy/policies you want to attach to this role, you can also create a customized policy to restrict the access permission other than granting write/read permission on…

Wenhe Qi

A lifelong learner who has enthusiasm for sharing knowledge; a developer who loves bringing ideas to life.

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