Send Emails Using Gmail from Android Application with Kotlin

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

386 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

671 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

320 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

525 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

Working with RecyclerView in an Android App Using Kotlin

Azhar
Updated on 21-Jul-2020 08:59:55

4K+ Views

This example demonstrates how to Work with RecyclerView in an Android App 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.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() {    private val movieList = ArrayList()    private lateinit var moviesAdapter: MoviesAdapter    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       ... Read More

Encode N-ary Tree to Binary Tree in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:57:15

586 Views

Suppose we have a N-ary tree. We have to encode that tree into one binary. We also have to make deserializer to deserialize the binary tree to N-ary tree.So, if the input is likethen the output will beTo solve this, we will follow these steps −Define a function encode(), this will take root, if root is valid, then −return nullnode = new tree node with value of rootif size of children of root is not 0, then −left of node := encode(children[0] of root)curr = left of nodefor initialize i := 1, when i < size of children of root, ... Read More

Serialize and Deserialize N-ary Tree in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:53:52

408 Views

Suppose we have one N-ary tree and we have to serialize and deserialize them. As we know that the serialization is the process of converting a data structure or object into a sequence of bits so we can store them in a file or memory buffer, and that can be reconstructed later in the same or another computer environment.Here we have to devise an algorithm to serialize and deserialize an N-ary tree. The N-ary tree is a rooted tree in which each node has no more than N children.So, if the input is likethen the output will be Serialize: 1 ... Read More

Advertisements