Monday, May 18, 2020

error: ‘std::vector’ is not a type


int singleNumber( std::vector& nums )


solution:

you have to declare the type.



most of the c++ code that gets copied to html gets truncated and thus this happens. Following can help

https://mihirknows.blogspot.com/2020/05/code-template-in-blogger.html

Saturday, April 4, 2020

LeetCode : Single Number (C++)

Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4

Solution :

LeetCode: Contains Duplicate (c++)

Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
Input: [1,2,3,1]
Output: true
Example 2:
Input: [1,2,3,4]
Output: false
Example 3:
Input: [1,1,1,3,3,4,3,2,4,2]
Output: true

LeetCode : Solution Rotate Array (C++)

Given an array, rotate the array to the right by k steps, where k is non-negative.
Example 1:
Input: [1,2,3,4,5,6,7] and k = 3
Output: [5,6,7,1,2,3,4]
Explanation:
rotate 1 steps to the right: [7,1,2,3,4,5,6]
rotate 2 steps to the right: [6,7,1,2,3,4,5]
rotate 3 steps to the right: [5,6,7,1,2,3,4]
Example 2:
Input: [-1,-100,3,99] and k = 2
Output: [3,99,-1,-100]
Explanation: 
rotate 1 steps to the right: [99,-1,-100,3]
rotate 2 steps to the right: [3,99,-1,-100]
Note:
  • Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.
  • Could you do it in-place with O(1) extra space?

LeetCode : Solution Best Time to Buy and Sell Stock II Solution (C++)

Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).
Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

Friday, April 3, 2020

debian how to open a folder in same gui


if you have the above issue.

1. go to System>Preference>File Management
2. select Behavior tab
3. tick the "Always open in browser windows


now the browsing would be via browser



Monday, February 17, 2020

create multiple files with single command in linux

touch {events.txt,app.txt,hello.txt} 

will create multiple files 




or a regex can be used as shown bellow.


touch hello{1..10}.txt


Create Multiple Subdirectories with One Linux Command

mkdir -p  src/{dir1,dir2,dir3,images/{im1,im2,im3}}

above command creates all with structure 



Tuesday, January 7, 2020

NTP Time Sync single shot

NTP time sync, previously was done using ntpdate and it was deprecated as of September 2012. ntpd provides same functionality from then on using following.

ntpd -gqx






NOTE:- one needs to setup the /etc/ntp.conf file.


-g
Normally, ntpd exits with a message to the system log if the offset exceeds the panic threshold, which is 1000 s by default. This option allows the time to be set to any value without restriction; however, this can happen only once. If the threshold is exceeded after that, ntpd will exit with a message to the system log. This option can be used with the -q and -x options. See the tinker command for other options.


-q
Exit the ntpd just after the first time the clock is set. This behavior mimics that of the ntpdate program, which is to be retired. The -g and -x options can be used with this option. Note: The kernel time discipline is disabled with this option.



-x
Normally, the time is slewed if the offset is less than the step threshold, which is 128 ms by default, and stepped if above the threshold. This option sets the threshold to 600 s, which is well within the accuracy window to set the clock manually. Note: Since the slew rate of typical Unix kernels is limited to 0.5 ms/s, each second of adjustment requires an amortization interval of 2000 s. Thus, an adjustment as much as 600 s will take almost 14 days to complete. This option can be used with the -g and -q options. See the tinker command for other options. Note: The kernel time discipline is disabled with this option.


Monday, January 6, 2020

Fixed: blurry font fix on vm ( virtual machine )

Problem : Blurry font on the virtual machine screen.


Solution:

1. change the above setting to remove selection of both Keep Aspect Ratio Stretch and Free Stretch.
2. screen may resize.
3. if the fonts are still not fixed then you may need to change the screen resolution in VM to your screen resolution.



4. I changed mine to 2560 x 1600 (16:10)


NOTE: This sort of issue are due to Aspect Ratio mainly.