The Maze III in C++

Arnab Chakraborty
Updated on 21-Jul-2020 09:13:05

519 Views

Suppose there is a maze with empty spaces and walls and there is also a ball in that maze. The ball can go through empty spaces by rolling up (u), down (d), left (l) or right (r) directions, but it keeps rolling until hitting a wall. When the ball stops, it could choose the next direction. One hole is also in that maze. The ball will drop into the hole if it rolls on to the hole.So if we have the ball position, the hole position and the maze, we have to find out how the ball could drop into ... Read More

Convert Drawable to Bitmap in Android Using Kotlin

Azhar
Updated on 21-Jul-2020 09:13:02

3K+ Views

This example demonstrates how to convert a Drawable to a Bitmap in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.BitmapFactory import android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val imageView: ... Read More

Substring with Concatenation of All Words in C++ Program

Arnab Chakraborty
Updated on 21-Jul-2020 09:09:36

226 Views

Suppose we have a string, s, and we also have a list of words, words present in the array are all of the same length. We have to find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.So if the input is like “barfoothefoobarman” and words are [“foo”, “bar”], then the output will be [0, 9]. This is because the substring starting at index 0 and 9 are “barfoo” and “foobar”.To solve this, we will follow these steps −Define a method called ok(), this will take ... Read More

Send Emails Using Gmail from Android Application with Kotlin

Azhar
Updated on 21-Jul-2020 09:07:32

393 Views

This example demonstrates how to send emails using gmail from my Android application using Kotlin.Step 1 − Create a new project in Android Studio, go to File ? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var editTextMail: EditText    lateinit var editTextSubject: EditText    lateinit var editTextMessage: EditText    lateinit var buttonSend: Button   ... Read More

Encode String with Shortest Length in C++

Arnab Chakraborty
Updated on 21-Jul-2020 09:06:42

681 Views

Suppose we have a non-empty string; we have to encode this string such that its encoded length will be minimum.The encoding rule is like − k[encoded_string], where the encoded_string inside [ ] is being repeated exactly k times. We have to keep in mind that k will be a positive integer and encoded string will not be empty or have extra space. We can assume that the input string contains only lowercase letters. If the encoding process does not make the string shorter, then do not encode that string.So, if the input is like "aaaaa", then the output will be ... Read More

Send Emails Using Gmail from Android Application with Kotlin

Azhar
Updated on 21-Jul-2020 09:06:22

2K+ Views

This example demonstrates how to send emails using gmail from my Android application using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                             Step 3 − Add the following code to MainActivity.ktimport android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var editTextMail: EditText    lateinit var editTextSubject: EditText    lateinit var editTextMessage: ... Read More

Count the Repetitions in C++

Arnab Chakraborty
Updated on 21-Jul-2020 09:04:48

329 Views

Suppose we have two non-empty strings s1 and s2 (maximum 100 characters) and two numbers n1 and n2 both are in range 0 to 106. Now suppose the strings S1 and S2, where S1=[s1, n1] and S2=[s2, n2].S = [s, n] defines the string S which consists of n connected strings s. As an exdample, ["ab", 4] ="abababab".On the other hand, we cal also define that string s1 can be obtained from string s2 if we remove some characters from s2 such that it becomes s1. So, "abc" can be obtained from "abdbec" based on the definition, but it can ... Read More

Read Files from Assets on Android Using Kotlin

Azhar
Updated on 21-Jul-2020 09:03:05

4K+ Views

This example demonstrates how to read files from assets on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Right click app >> New >> Folder >> Assets folder. Right click on the assets folder, select New >> file (myText.txt) and your text.Step 4 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.io.IOException import java.io.InputStream class MainActivity : AppCompatActivity() { ... Read More

Optimal Account Balancing in C++

Arnab Chakraborty
Updated on 21-Jul-2020 09:02:52

537 Views

Suppose a group of friends went on holiday and sometimes they lent each other money. So as an example, Amit paid for Bikram's lunch for $10. Then later Chandan gave Amit $5 for a taxi fare. We have to design a model where each transaction is taken as a tuple (x, y, z) which means person x gave person y $z.Assuming Amit, Bikram, and Chandan are person 0, 1, and 2 respectively the transactions can be represented as [[0, 1, 10], [2, 0, 5]]. If we have a list of transactions between a group of people, we have to find ... Read More

LFU Cache in Python

Arnab Chakraborty
Updated on 21-Jul-2020 09:00:43

2K+ Views

Suppose we want to design and implement a data structure for Least Frequently Used (LFU) cache system. It should support the following operations −get(key) – This will be used to get the value of the key if the key exists in the cache, otherwise return -1.put(key, value) – This will be used to set or insert the value if the key is not already present.When the cache reached its maximum capacity, it should invalidate the least frequently used element before inserting a new element.So, if the LFUCache is initialized with capacity 2 and call these methods cache.put(1, 1); cache.put(2, 2); ... Read More

Advertisements